regexp是go支持正则表达式的相关内置模块。
一、引入
import "regexp"
二、使用
2.1 regexp.MatchString 使用正则表达式匹配字符串
match, _ := regexp.MatchString("H(.*)!", "Hello world!")
fmt.Println(match) // true
2.2 regexp.Match 使用正则表达式匹配字符串
match, _ := regexp.Match("H(.*)!", []byte("Hello World!"))
fmt.Println(match) // true
2.3 regexp.Compile 使用正则表达式匹配字符串
compile, _ := regexp.Compile("H(.*)!")
compileMatch := compile.MatchString("Hello World!")
fmt.Println(compileMatch) // true
2.4 compile.FindString 返回匹配到的字符串

最低0.47元/天 解锁文章
2749

被折叠的 条评论
为什么被折叠?



