Change-Id: I0bbb53cad9a7c464ab1cfca381128f33496813ff
Reviewed-on: https://go-review.googlesource.com/49130
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
// 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"))
}
}
-// 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