文档
- https://golang.google.cn/pkg/regexp/#example_MatchString
方法签名
func MatchString(pattern string, s string) (matched bool, err error)
示例
package mainimport ("fmt""regexp"
)func main() {matched, err := regexp.MatchString(`foo.*`, "seafood")fmt.Println(matched, err)matched, err = regexp.MatchString(`bar.*`, "seafood")fmt.Println(matched, err)matched, err = regexp.MatchString(`a(b`, "seafood")fmt.Println(matched, err)
}
输出
true <nil>
false <nil>
false error parsing regexp: missing closing ): `a(b`