Commit 3885e864 authored by Matthew Broberg's avatar Matthew Broberg Committed by Brad Fitzpatrick

regexp: add QuoteMeta example

Change-Id: I0bbb53cad9a7c464ab1cfca381128f33496813ff
Reviewed-on: https://go-review.googlesource.com/49130Reviewed-by: default avatarBrad Fitzpatrick <bradfitz@golang.org>
parent 2cf9732e
......@@ -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"))
......
......@@ -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
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment