Commit 55c55dda authored by Vladimir Kovpak's avatar Vladimir Kovpak Committed by Rob Pike

regexp: use backquotes for all regular expression examples

This commit performs replace double quote to backquote,
so now all examples looks consistent.

Change-Id: I8cf760ce1bdeff9619a88e531161b9516385241b
GitHub-Last-Rev: e3e636cebbf41528b8a73f9a3fe5afa10876f964
GitHub-Pull-Request: golang/go#28879
Reviewed-on: https://go-review.googlesource.com/c/150397Reviewed-by: default avatarRob Pike <r@golang.org>
Run-TryBot: Rob Pike <r@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
parent 48521848
...@@ -40,11 +40,11 @@ func ExampleMatch() { ...@@ -40,11 +40,11 @@ func ExampleMatch() {
} }
func ExampleMatchString() { func ExampleMatchString() {
matched, err := regexp.MatchString("foo.*", "seafood") matched, err := regexp.MatchString(`foo.*`, "seafood")
fmt.Println(matched, err) fmt.Println(matched, err)
matched, err = regexp.MatchString("bar.*", "seafood") matched, err = regexp.MatchString(`bar.*`, "seafood")
fmt.Println(matched, err) fmt.Println(matched, err)
matched, err = regexp.MatchString("a(b", "seafood") matched, err = regexp.MatchString(`a(b`, "seafood")
fmt.Println(matched, err) fmt.Println(matched, err)
// Output: // Output:
// true <nil> // true <nil>
...@@ -53,13 +53,13 @@ func ExampleMatchString() { ...@@ -53,13 +53,13 @@ func ExampleMatchString() {
} }
func ExampleQuoteMeta() { func ExampleQuoteMeta() {
fmt.Println(regexp.QuoteMeta("Escaping symbols like: .+*?()|[]{}^$")) fmt.Println(regexp.QuoteMeta(`Escaping symbols like: .+*?()|[]{}^$`))
// Output: // Output:
// Escaping symbols like: \.\+\*\?\(\)\|\[\]\{\}\^\$ // Escaping symbols like: \.\+\*\?\(\)\|\[\]\{\}\^\$
} }
func ExampleRegexp_Find() { func ExampleRegexp_Find() {
re := regexp.MustCompile("foo.?") re := regexp.MustCompile(`foo.?`)
fmt.Printf("%q\n", re.Find([]byte(`seafood fool`))) fmt.Printf("%q\n", re.Find([]byte(`seafood fool`)))
// Output: // Output:
...@@ -67,7 +67,7 @@ func ExampleRegexp_Find() { ...@@ -67,7 +67,7 @@ func ExampleRegexp_Find() {
} }
func ExampleRegexp_FindAll() { func ExampleRegexp_FindAll() {
re := regexp.MustCompile("foo.?") re := regexp.MustCompile(`foo.?`)
fmt.Printf("%q\n", re.FindAll([]byte(`seafood fool`), -1)) fmt.Printf("%q\n", re.FindAll([]byte(`seafood fool`), -1))
// Output: // Output:
...@@ -75,7 +75,7 @@ func ExampleRegexp_FindAll() { ...@@ -75,7 +75,7 @@ func ExampleRegexp_FindAll() {
} }
func ExampleRegexp_FindAllSubmatch() { func ExampleRegexp_FindAllSubmatch() {
re := regexp.MustCompile("foo(.?)") re := regexp.MustCompile(`foo(.?)`)
fmt.Printf("%q\n", re.FindAllSubmatch([]byte(`seafood fool`), -1)) fmt.Printf("%q\n", re.FindAllSubmatch([]byte(`seafood fool`), -1))
// Output: // Output:
...@@ -83,7 +83,7 @@ func ExampleRegexp_FindAllSubmatch() { ...@@ -83,7 +83,7 @@ func ExampleRegexp_FindAllSubmatch() {
} }
func ExampleRegexp_FindSubmatch() { func ExampleRegexp_FindSubmatch() {
re := regexp.MustCompile("foo(.?)") re := regexp.MustCompile(`foo(.?)`)
fmt.Printf("%q\n", re.FindSubmatch([]byte(`seafood fool`))) fmt.Printf("%q\n", re.FindSubmatch([]byte(`seafood fool`)))
// Output: // Output:
...@@ -91,7 +91,7 @@ func ExampleRegexp_FindSubmatch() { ...@@ -91,7 +91,7 @@ func ExampleRegexp_FindSubmatch() {
} }
func ExampleRegexp_Match() { func ExampleRegexp_Match() {
re := regexp.MustCompile("foo.?") re := regexp.MustCompile(`foo.?`)
fmt.Println(re.Match([]byte(`seafood fool`))) fmt.Println(re.Match([]byte(`seafood fool`)))
// Output: // Output:
...@@ -99,7 +99,7 @@ func ExampleRegexp_Match() { ...@@ -99,7 +99,7 @@ func ExampleRegexp_Match() {
} }
func ExampleRegexp_FindString() { func ExampleRegexp_FindString() {
re := regexp.MustCompile("foo.?") re := regexp.MustCompile(`foo.?`)
fmt.Printf("%q\n", re.FindString("seafood fool")) fmt.Printf("%q\n", re.FindString("seafood fool"))
fmt.Printf("%q\n", re.FindString("meat")) fmt.Printf("%q\n", re.FindString("meat"))
// Output: // Output:
...@@ -108,7 +108,7 @@ func ExampleRegexp_FindString() { ...@@ -108,7 +108,7 @@ func ExampleRegexp_FindString() {
} }
func ExampleRegexp_FindStringIndex() { func ExampleRegexp_FindStringIndex() {
re := regexp.MustCompile("ab?") re := regexp.MustCompile(`ab?`)
fmt.Println(re.FindStringIndex("tablett")) fmt.Println(re.FindStringIndex("tablett"))
fmt.Println(re.FindStringIndex("foo") == nil) fmt.Println(re.FindStringIndex("foo") == nil)
// Output: // Output:
...@@ -117,7 +117,7 @@ func ExampleRegexp_FindStringIndex() { ...@@ -117,7 +117,7 @@ func ExampleRegexp_FindStringIndex() {
} }
func ExampleRegexp_FindStringSubmatch() { func ExampleRegexp_FindStringSubmatch() {
re := regexp.MustCompile("a(x*)b(y|z)c") re := regexp.MustCompile(`a(x*)b(y|z)c`)
fmt.Printf("%q\n", re.FindStringSubmatch("-axxxbyc-")) fmt.Printf("%q\n", re.FindStringSubmatch("-axxxbyc-"))
fmt.Printf("%q\n", re.FindStringSubmatch("-abzc-")) fmt.Printf("%q\n", re.FindStringSubmatch("-abzc-"))
// Output: // Output:
...@@ -126,7 +126,7 @@ func ExampleRegexp_FindStringSubmatch() { ...@@ -126,7 +126,7 @@ func ExampleRegexp_FindStringSubmatch() {
} }
func ExampleRegexp_FindAllString() { func ExampleRegexp_FindAllString() {
re := regexp.MustCompile("a.") re := regexp.MustCompile(`a.`)
fmt.Println(re.FindAllString("paranormal", -1)) fmt.Println(re.FindAllString("paranormal", -1))
fmt.Println(re.FindAllString("paranormal", 2)) fmt.Println(re.FindAllString("paranormal", 2))
fmt.Println(re.FindAllString("graal", -1)) fmt.Println(re.FindAllString("graal", -1))
...@@ -139,7 +139,7 @@ func ExampleRegexp_FindAllString() { ...@@ -139,7 +139,7 @@ func ExampleRegexp_FindAllString() {
} }
func ExampleRegexp_FindAllStringSubmatch() { func ExampleRegexp_FindAllStringSubmatch() {
re := regexp.MustCompile("a(x*)b") re := regexp.MustCompile(`a(x*)b`)
fmt.Printf("%q\n", re.FindAllStringSubmatch("-ab-", -1)) fmt.Printf("%q\n", re.FindAllStringSubmatch("-ab-", -1))
fmt.Printf("%q\n", re.FindAllStringSubmatch("-axxb-", -1)) fmt.Printf("%q\n", re.FindAllStringSubmatch("-axxb-", -1))
fmt.Printf("%q\n", re.FindAllStringSubmatch("-ab-axb-", -1)) fmt.Printf("%q\n", re.FindAllStringSubmatch("-ab-axb-", -1))
...@@ -152,7 +152,7 @@ func ExampleRegexp_FindAllStringSubmatch() { ...@@ -152,7 +152,7 @@ func ExampleRegexp_FindAllStringSubmatch() {
} }
func ExampleRegexp_FindAllStringSubmatchIndex() { func ExampleRegexp_FindAllStringSubmatchIndex() {
re := regexp.MustCompile("a(x*)b") re := regexp.MustCompile(`a(x*)b`)
// Indices: // Indices:
// 01234567 012345678 // 01234567 012345678
// -ab-axb- -axxb-ab- // -ab-axb- -axxb-ab-
...@@ -170,7 +170,7 @@ func ExampleRegexp_FindAllStringSubmatchIndex() { ...@@ -170,7 +170,7 @@ func ExampleRegexp_FindAllStringSubmatchIndex() {
} }
func ExampleRegexp_MatchString() { func ExampleRegexp_MatchString() {
re := regexp.MustCompile("(gopher){2}") re := regexp.MustCompile(`(gopher){2}`)
fmt.Println(re.MatchString("gopher")) fmt.Println(re.MatchString("gopher"))
fmt.Println(re.MatchString("gophergopher")) fmt.Println(re.MatchString("gophergopher"))
fmt.Println(re.MatchString("gophergophergopher")) fmt.Println(re.MatchString("gophergophergopher"))
...@@ -181,7 +181,7 @@ func ExampleRegexp_MatchString() { ...@@ -181,7 +181,7 @@ func ExampleRegexp_MatchString() {
} }
func ExampleRegexp_ReplaceAllLiteralString() { func ExampleRegexp_ReplaceAllLiteralString() {
re := regexp.MustCompile("a(x*)b") re := regexp.MustCompile(`a(x*)b`)
fmt.Println(re.ReplaceAllLiteralString("-ab-axxb-", "T")) fmt.Println(re.ReplaceAllLiteralString("-ab-axxb-", "T"))
fmt.Println(re.ReplaceAllLiteralString("-ab-axxb-", "$1")) fmt.Println(re.ReplaceAllLiteralString("-ab-axxb-", "$1"))
fmt.Println(re.ReplaceAllLiteralString("-ab-axxb-", "${1}")) fmt.Println(re.ReplaceAllLiteralString("-ab-axxb-", "${1}"))
...@@ -192,7 +192,7 @@ func ExampleRegexp_ReplaceAllLiteralString() { ...@@ -192,7 +192,7 @@ func ExampleRegexp_ReplaceAllLiteralString() {
} }
func ExampleRegexp_ReplaceAllString() { func ExampleRegexp_ReplaceAllString() {
re := regexp.MustCompile("a(x*)b") re := regexp.MustCompile(`a(x*)b`)
fmt.Println(re.ReplaceAllString("-ab-axxb-", "T")) fmt.Println(re.ReplaceAllString("-ab-axxb-", "T"))
fmt.Println(re.ReplaceAllString("-ab-axxb-", "$1")) fmt.Println(re.ReplaceAllString("-ab-axxb-", "$1"))
fmt.Println(re.ReplaceAllString("-ab-axxb-", "$1W")) fmt.Println(re.ReplaceAllString("-ab-axxb-", "$1W"))
...@@ -205,7 +205,7 @@ func ExampleRegexp_ReplaceAllString() { ...@@ -205,7 +205,7 @@ func ExampleRegexp_ReplaceAllString() {
} }
func ExampleRegexp_SubexpNames() { func ExampleRegexp_SubexpNames() {
re := regexp.MustCompile("(?P<first>[a-zA-Z]+) (?P<last>[a-zA-Z]+)") re := regexp.MustCompile(`(?P<first>[a-zA-Z]+) (?P<last>[a-zA-Z]+)`)
fmt.Println(re.MatchString("Alan Turing")) fmt.Println(re.MatchString("Alan Turing"))
fmt.Printf("%q\n", re.SubexpNames()) fmt.Printf("%q\n", re.SubexpNames())
reversed := fmt.Sprintf("${%s} ${%s}", re.SubexpNames()[2], re.SubexpNames()[1]) reversed := fmt.Sprintf("${%s} ${%s}", re.SubexpNames()[2], re.SubexpNames()[1])
...@@ -219,12 +219,12 @@ func ExampleRegexp_SubexpNames() { ...@@ -219,12 +219,12 @@ func ExampleRegexp_SubexpNames() {
} }
func ExampleRegexp_Split() { func ExampleRegexp_Split() {
a := regexp.MustCompile("a") a := regexp.MustCompile(`a`)
fmt.Println(a.Split("banana", -1)) fmt.Println(a.Split("banana", -1))
fmt.Println(a.Split("banana", 0)) fmt.Println(a.Split("banana", 0))
fmt.Println(a.Split("banana", 1)) fmt.Println(a.Split("banana", 1))
fmt.Println(a.Split("banana", 2)) fmt.Println(a.Split("banana", 2))
zp := regexp.MustCompile("z+") zp := regexp.MustCompile(`z+`)
fmt.Println(zp.Split("pizza", -1)) fmt.Println(zp.Split("pizza", -1))
fmt.Println(zp.Split("pizza", 0)) fmt.Println(zp.Split("pizza", 0))
fmt.Println(zp.Split("pizza", 1)) fmt.Println(zp.Split("pizza", 1))
......
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