Skip to content

Commit 55c55dd

Browse files
cn0047robpike
authored andcommitted
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: e3e636c GitHub-Pull-Request: #28879 Reviewed-on: https://go-review.googlesource.com/c/150397 Reviewed-by: Rob Pike <[email protected]> Run-TryBot: Rob Pike <[email protected]> TryBot-Result: Gobot Gobot <[email protected]>
1 parent 4852184 commit 55c55dd

File tree

1 file changed

+21
-21
lines changed

1 file changed

+21
-21
lines changed

src/regexp/example_test.go

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,11 @@ func ExampleMatch() {
4040
}
4141

4242
func ExampleMatchString() {
43-
matched, err := regexp.MatchString("foo.*", "seafood")
43+
matched, err := regexp.MatchString(`foo.*`, "seafood")
4444
fmt.Println(matched, err)
45-
matched, err = regexp.MatchString("bar.*", "seafood")
45+
matched, err = regexp.MatchString(`bar.*`, "seafood")
4646
fmt.Println(matched, err)
47-
matched, err = regexp.MatchString("a(b", "seafood")
47+
matched, err = regexp.MatchString(`a(b`, "seafood")
4848
fmt.Println(matched, err)
4949
// Output:
5050
// true <nil>
@@ -53,53 +53,53 @@ func ExampleMatchString() {
5353
}
5454

5555
func ExampleQuoteMeta() {
56-
fmt.Println(regexp.QuoteMeta("Escaping symbols like: .+*?()|[]{}^$"))
56+
fmt.Println(regexp.QuoteMeta(`Escaping symbols like: .+*?()|[]{}^$`))
5757
// Output:
5858
// Escaping symbols like: \.\+\*\?\(\)\|\[\]\{\}\^\$
5959
}
6060

6161
func ExampleRegexp_Find() {
62-
re := regexp.MustCompile("foo.?")
62+
re := regexp.MustCompile(`foo.?`)
6363
fmt.Printf("%q\n", re.Find([]byte(`seafood fool`)))
6464

6565
// Output:
6666
// "food"
6767
}
6868

6969
func ExampleRegexp_FindAll() {
70-
re := regexp.MustCompile("foo.?")
70+
re := regexp.MustCompile(`foo.?`)
7171
fmt.Printf("%q\n", re.FindAll([]byte(`seafood fool`), -1))
7272

7373
// Output:
7474
// ["food" "fool"]
7575
}
7676

7777
func ExampleRegexp_FindAllSubmatch() {
78-
re := regexp.MustCompile("foo(.?)")
78+
re := regexp.MustCompile(`foo(.?)`)
7979
fmt.Printf("%q\n", re.FindAllSubmatch([]byte(`seafood fool`), -1))
8080

8181
// Output:
8282
// [["food" "d"] ["fool" "l"]]
8383
}
8484

8585
func ExampleRegexp_FindSubmatch() {
86-
re := regexp.MustCompile("foo(.?)")
86+
re := regexp.MustCompile(`foo(.?)`)
8787
fmt.Printf("%q\n", re.FindSubmatch([]byte(`seafood fool`)))
8888

8989
// Output:
9090
// ["food" "d"]
9191
}
9292

9393
func ExampleRegexp_Match() {
94-
re := regexp.MustCompile("foo.?")
94+
re := regexp.MustCompile(`foo.?`)
9595
fmt.Println(re.Match([]byte(`seafood fool`)))
9696

9797
// Output:
9898
// true
9999
}
100100

101101
func ExampleRegexp_FindString() {
102-
re := regexp.MustCompile("foo.?")
102+
re := regexp.MustCompile(`foo.?`)
103103
fmt.Printf("%q\n", re.FindString("seafood fool"))
104104
fmt.Printf("%q\n", re.FindString("meat"))
105105
// Output:
@@ -108,7 +108,7 @@ func ExampleRegexp_FindString() {
108108
}
109109

110110
func ExampleRegexp_FindStringIndex() {
111-
re := regexp.MustCompile("ab?")
111+
re := regexp.MustCompile(`ab?`)
112112
fmt.Println(re.FindStringIndex("tablett"))
113113
fmt.Println(re.FindStringIndex("foo") == nil)
114114
// Output:
@@ -117,7 +117,7 @@ func ExampleRegexp_FindStringIndex() {
117117
}
118118

119119
func ExampleRegexp_FindStringSubmatch() {
120-
re := regexp.MustCompile("a(x*)b(y|z)c")
120+
re := regexp.MustCompile(`a(x*)b(y|z)c`)
121121
fmt.Printf("%q\n", re.FindStringSubmatch("-axxxbyc-"))
122122
fmt.Printf("%q\n", re.FindStringSubmatch("-abzc-"))
123123
// Output:
@@ -126,7 +126,7 @@ func ExampleRegexp_FindStringSubmatch() {
126126
}
127127

128128
func ExampleRegexp_FindAllString() {
129-
re := regexp.MustCompile("a.")
129+
re := regexp.MustCompile(`a.`)
130130
fmt.Println(re.FindAllString("paranormal", -1))
131131
fmt.Println(re.FindAllString("paranormal", 2))
132132
fmt.Println(re.FindAllString("graal", -1))
@@ -139,7 +139,7 @@ func ExampleRegexp_FindAllString() {
139139
}
140140

141141
func ExampleRegexp_FindAllStringSubmatch() {
142-
re := regexp.MustCompile("a(x*)b")
142+
re := regexp.MustCompile(`a(x*)b`)
143143
fmt.Printf("%q\n", re.FindAllStringSubmatch("-ab-", -1))
144144
fmt.Printf("%q\n", re.FindAllStringSubmatch("-axxb-", -1))
145145
fmt.Printf("%q\n", re.FindAllStringSubmatch("-ab-axb-", -1))
@@ -152,7 +152,7 @@ func ExampleRegexp_FindAllStringSubmatch() {
152152
}
153153

154154
func ExampleRegexp_FindAllStringSubmatchIndex() {
155-
re := regexp.MustCompile("a(x*)b")
155+
re := regexp.MustCompile(`a(x*)b`)
156156
// Indices:
157157
// 01234567 012345678
158158
// -ab-axb- -axxb-ab-
@@ -170,7 +170,7 @@ func ExampleRegexp_FindAllStringSubmatchIndex() {
170170
}
171171

172172
func ExampleRegexp_MatchString() {
173-
re := regexp.MustCompile("(gopher){2}")
173+
re := regexp.MustCompile(`(gopher){2}`)
174174
fmt.Println(re.MatchString("gopher"))
175175
fmt.Println(re.MatchString("gophergopher"))
176176
fmt.Println(re.MatchString("gophergophergopher"))
@@ -181,7 +181,7 @@ func ExampleRegexp_MatchString() {
181181
}
182182

183183
func ExampleRegexp_ReplaceAllLiteralString() {
184-
re := regexp.MustCompile("a(x*)b")
184+
re := regexp.MustCompile(`a(x*)b`)
185185
fmt.Println(re.ReplaceAllLiteralString("-ab-axxb-", "T"))
186186
fmt.Println(re.ReplaceAllLiteralString("-ab-axxb-", "$1"))
187187
fmt.Println(re.ReplaceAllLiteralString("-ab-axxb-", "${1}"))
@@ -192,7 +192,7 @@ func ExampleRegexp_ReplaceAllLiteralString() {
192192
}
193193

194194
func ExampleRegexp_ReplaceAllString() {
195-
re := regexp.MustCompile("a(x*)b")
195+
re := regexp.MustCompile(`a(x*)b`)
196196
fmt.Println(re.ReplaceAllString("-ab-axxb-", "T"))
197197
fmt.Println(re.ReplaceAllString("-ab-axxb-", "$1"))
198198
fmt.Println(re.ReplaceAllString("-ab-axxb-", "$1W"))
@@ -205,7 +205,7 @@ func ExampleRegexp_ReplaceAllString() {
205205
}
206206

207207
func ExampleRegexp_SubexpNames() {
208-
re := regexp.MustCompile("(?P<first>[a-zA-Z]+) (?P<last>[a-zA-Z]+)")
208+
re := regexp.MustCompile(`(?P<first>[a-zA-Z]+) (?P<last>[a-zA-Z]+)`)
209209
fmt.Println(re.MatchString("Alan Turing"))
210210
fmt.Printf("%q\n", re.SubexpNames())
211211
reversed := fmt.Sprintf("${%s} ${%s}", re.SubexpNames()[2], re.SubexpNames()[1])
@@ -219,12 +219,12 @@ func ExampleRegexp_SubexpNames() {
219219
}
220220

221221
func ExampleRegexp_Split() {
222-
a := regexp.MustCompile("a")
222+
a := regexp.MustCompile(`a`)
223223
fmt.Println(a.Split("banana", -1))
224224
fmt.Println(a.Split("banana", 0))
225225
fmt.Println(a.Split("banana", 1))
226226
fmt.Println(a.Split("banana", 2))
227-
zp := regexp.MustCompile("z+")
227+
zp := regexp.MustCompile(`z+`)
228228
fmt.Println(zp.Split("pizza", -1))
229229
fmt.Println(zp.Split("pizza", 0))
230230
fmt.Println(zp.Split("pizza", 1))

0 commit comments

Comments
 (0)