aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJosh Roppo <joshroppo@gmail.com>2017-07-15 13:40:22 -0700
committerBrad Fitzpatrick <bradfitz@golang.org>2017-07-15 21:13:35 +0000
commit9ca9f31f0b4c3fbe78a214a979e5aad409c16a48 (patch)
treea6194a4cb70584fe824966c1cb73bbab792c8f70
parentf062955ea78a4a57fbfe54fdc11b7aee7a1086d2 (diff)
downloadgo-9ca9f31f0b4c3fbe78a214a979e5aad409c16a48.tar.gz
go-9ca9f31f0b4c3fbe78a214a979e5aad409c16a48.zip
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>
-rw-r--r--src/regexp/example_test.go11
1 files changed, 11 insertions, 0 deletions
diff --git a/src/regexp/example_test.go b/src/regexp/example_test.go
index 8661d6d389..2ac92d4382 100644
--- a/src/regexp/example_test.go
+++ b/src/regexp/example_test.go
@@ -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"))