Browse Source

[add] FindIPv4

bvbej 2 years ago
parent
commit
e3d8e4b125
2 changed files with 9 additions and 0 deletions
  1. 1 0
      .gitignore
  2. 8 0
      tool/assist/tool.go

+ 1 - 0
.gitignore

@@ -2,3 +2,4 @@
 /vendor
 
 *.yaml.json
+*_test.go

+ 8 - 0
tool/assist/tool.go

@@ -5,6 +5,7 @@ import (
 	"git.bvbej.com/bvbej/base-golang/pkg/time_parse"
 	"math"
 	"math/rand"
+	"regexp"
 	"strconv"
 	"time"
 	"unicode"
@@ -83,3 +84,10 @@ func Uint64UniqueInArray(valueArray []uint64) []uint64 {
 	}
 	return result
 }
+
+func FindIPv4(input string) string {
+	partIp := "(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])"
+	must := partIp + "\\." + partIp + "\\." + partIp + "\\." + partIp
+	matchMe := regexp.MustCompile(must)
+	return matchMe.FindString(input)
+}