]> Cypherpunks repositories - gostls13.git/commitdiff
regexp: example for MatchString function
authorJosh Roppo <joshroppo@gmail.com>
Sat, 15 Jul 2017 20:40:22 +0000 (13:40 -0700)
committerBrad Fitzpatrick <bradfitz@golang.org>
Sat, 15 Jul 2017 21:13:35 +0000 (21:13 +0000)
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>

src/regexp/example_test.go

index 8661d6d389df4c42d38a1018ffeafe92967d0754..2ac92d43820697c84b211d174109a5003bf91bda 100644 (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"))