Skip to content

Commit

Permalink
add KeepRegexCharacter
Browse files Browse the repository at this point in the history
  • Loading branch information
xurwxj committed May 27, 2021
1 parent 992526e commit dae2017
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
13 changes: 13 additions & 0 deletions base/string.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,3 +177,16 @@ func HasJPReg(data string) bool {
}
return false
}

// KeepRegexCharacter keep all character matched in regex
func KeepRegexCharacter(str, regexStr string) (rs string, err error) {
if str == "" {
return
}
reg, err := regexp.Compile(regexStr)
if err != nil {
return
}
rs = reg.ReplaceAllString(str, "")
return
}
8 changes: 7 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,13 @@ import (
)

func main() {
vs()
dt()
}

func dt() {
s, r := base.KeepRegexCharacter("ex v1.2.3 data", "[a-zA-Z]")
fmt.Println(s)
fmt.Println(r)
}

func vs() {
Expand Down

0 comments on commit dae2017

Please sign in to comment.