]> Cypherpunks repositories - gostls13.git/commitdiff
regexp: add QuoteMeta example
authorMatthew Broberg <gogetmb@gmail.com>
Sat, 15 Jul 2017 23:40:29 +0000 (17:40 -0600)
committerBrad Fitzpatrick <bradfitz@golang.org>
Tue, 12 Jun 2018 22:37:01 +0000 (22:37 +0000)
Change-Id: I0bbb53cad9a7c464ab1cfca381128f33496813ff
Reviewed-on: https://go-review.googlesource.com/49130
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
src/regexp/example_test.go
src/regexp/regexp.go

index 0bf1f6bee76d0fc3c94aa3a3f38dae758d8de1e8..eb8cd4ea94c3d123b801f6e7ebfb1d4d76db64b1 100644 (file)
@@ -38,6 +38,12 @@ func ExampleMatchString() {
        // false error parsing regexp: missing closing ): `a(b`
 }
 
+func ExampleQuoteMeta() {
+       fmt.Println(regexp.QuoteMeta("Escaping symbols like: .+*?()|[]{}^$"))
+       // Output:
+       // Escaping symbols like: \.\+\*\?\(\)\|\[\]\{\}\^\$
+}
+
 func ExampleRegexp_FindString() {
        re := regexp.MustCompile("foo.?")
        fmt.Printf("%q\n", re.FindString("seafood fool"))
index 09faced8f3f050da44be407dea0d32bf386bfb00..0d10aa1e225fb3cd37a42b47242d06bfed791c32 100644 (file)
@@ -616,9 +616,9 @@ func init() {
        }
 }
 
-// QuoteMeta returns a string that quotes all regular expression metacharacters
+// QuoteMeta returns a string that escapes all regular expression metacharacters
 // inside the argument text; the returned string is a regular expression matching
-// the literal text. For example, QuoteMeta(`[foo]`) returns `\[foo\]`.
+// the literal text.
 func QuoteMeta(s string) string {
        // A byte loop is correct because all metacharacters are ASCII.
        var i int