Skip to content

Commit

Permalink
Merge pull request #3 from GoCarnival/develop
Browse files Browse the repository at this point in the history
🚀 Deploy stuff.
  • Loading branch information
Ivan97 authored Apr 30, 2024
2 parents 62934b5 + 3f4b234 commit 8ed4297
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
4 changes: 4 additions & 0 deletions re.go
Original file line number Diff line number Diff line change
Expand Up @@ -435,3 +435,7 @@ func (e *Expression) GetTextGroups(str string, group int) []string {
}
return res
}

func (e *Expression) Regexp() *regexp.Regexp {
return e.regexp
}
14 changes: 14 additions & 0 deletions re_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,17 @@ func TestGroup(t *testing.T) {
t.Log(expression.GetText(str, "foo"))
t.Log(expression.GetTextGroups(str, 0))
}

func TestRegex(t *testing.T) {
//目标字符串
searchIn := "John: 2578.34 William: 4567.23 Steve: 5632.18"
//pattern := `[0-9]+\.[0-9]+` //正则表达式
expression := ExpressionBuilder().
Digit().OneOrMore().
Then("\\.").
Digit().OneOrMore().
Build()
t.Log(expression.String())
t.Log(expression.Test(searchIn))
t.Log(expression.Regexp().ReplaceAllString(searchIn, "##.#"))
}

0 comments on commit 8ed4297

Please sign in to comment.