1
0
mirror of https://github.com/golang/go synced 2024-11-23 20:30:04 -07:00

regexp: example for MatchString function

Change-Id: I5ca5a6689f0679154c24820466f5cf0011d0aaa6
Reviewed-on: https://go-review.googlesource.com/48959
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
Josh Roppo 2017-07-15 13:40:22 -07:00 committed by Brad Fitzpatrick
parent f062955ea7
commit 9ca9f31f0b

View File

@ -109,6 +109,17 @@ func ExampleRegexp_FindAllStringSubmatchIndex() {
// []
}
func ExampleRegexp_MatchString() {
re := regexp.MustCompile("(gopher){2}")
fmt.Println(re.MatchString("gopher"))
fmt.Println(re.MatchString("gophergopher"))
fmt.Println(re.MatchString("gophergophergopher"))
// Output:
// false
// true
// true
}
func ExampleRegexp_ReplaceAllLiteralString() {
re := regexp.MustCompile("a(x*)b")
fmt.Println(re.ReplaceAllLiteralString("-ab-axxb-", "T"))