}
func ExampleMatchString() {
- matched, err := regexp.MatchString("foo.*", "seafood")
+ matched, err := regexp.MatchString(`foo.*`, "seafood")
fmt.Println(matched, err)
- matched, err = regexp.MatchString("bar.*", "seafood")
+ matched, err = regexp.MatchString(`bar.*`, "seafood")
fmt.Println(matched, err)
- matched, err = regexp.MatchString("a(b", "seafood")
+ matched, err = regexp.MatchString(`a(b`, "seafood")
fmt.Println(matched, err)
// Output:
// true <nil>
}
func ExampleQuoteMeta() {
- fmt.Println(regexp.QuoteMeta("Escaping symbols like: .+*?()|[]{}^$"))
+ fmt.Println(regexp.QuoteMeta(`Escaping symbols like: .+*?()|[]{}^$`))
// Output:
// Escaping symbols like: \.\+\*\?\(\)\|\[\]\{\}\^\$
}
func ExampleRegexp_Find() {
- re := regexp.MustCompile("foo.?")
+ re := regexp.MustCompile(`foo.?`)
fmt.Printf("%q\n", re.Find([]byte(`seafood fool`)))
// Output:
}
func ExampleRegexp_FindAll() {
- re := regexp.MustCompile("foo.?")
+ re := regexp.MustCompile(`foo.?`)
fmt.Printf("%q\n", re.FindAll([]byte(`seafood fool`), -1))
// Output:
}
func ExampleRegexp_FindAllSubmatch() {
- re := regexp.MustCompile("foo(.?)")
+ re := regexp.MustCompile(`foo(.?)`)
fmt.Printf("%q\n", re.FindAllSubmatch([]byte(`seafood fool`), -1))
// Output:
}
func ExampleRegexp_FindSubmatch() {
- re := regexp.MustCompile("foo(.?)")
+ re := regexp.MustCompile(`foo(.?)`)
fmt.Printf("%q\n", re.FindSubmatch([]byte(`seafood fool`)))
// Output:
}
func ExampleRegexp_Match() {
- re := regexp.MustCompile("foo.?")
+ re := regexp.MustCompile(`foo.?`)
fmt.Println(re.Match([]byte(`seafood fool`)))
// Output:
}
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("meat"))
// Output:
}
func ExampleRegexp_FindStringIndex() {
- re := regexp.MustCompile("ab?")
+ re := regexp.MustCompile(`ab?`)
fmt.Println(re.FindStringIndex("tablett"))
fmt.Println(re.FindStringIndex("foo") == nil)
// Output:
}
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("-abzc-"))
// Output:
}
func ExampleRegexp_FindAllString() {
- re := regexp.MustCompile("a.")
+ re := regexp.MustCompile(`a.`)
fmt.Println(re.FindAllString("paranormal", -1))
fmt.Println(re.FindAllString("paranormal", 2))
fmt.Println(re.FindAllString("graal", -1))
}
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("-axxb-", -1))
fmt.Printf("%q\n", re.FindAllStringSubmatch("-ab-axb-", -1))
}
func ExampleRegexp_FindAllStringSubmatchIndex() {
- re := regexp.MustCompile("a(x*)b")
+ re := regexp.MustCompile(`a(x*)b`)
// Indices:
// 01234567 012345678
// -ab-axb- -axxb-ab-
}
func ExampleRegexp_MatchString() {
- re := regexp.MustCompile("(gopher){2}")
+ re := regexp.MustCompile(`(gopher){2}`)
fmt.Println(re.MatchString("gopher"))
fmt.Println(re.MatchString("gophergopher"))
fmt.Println(re.MatchString("gophergophergopher"))
}
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-", "$1"))
fmt.Println(re.ReplaceAllLiteralString("-ab-axxb-", "${1}"))
}
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-", "$1"))
fmt.Println(re.ReplaceAllString("-ab-axxb-", "$1W"))
}
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.Printf("%q\n", re.SubexpNames())
reversed := fmt.Sprintf("${%s} ${%s}", re.SubexpNames()[2], re.SubexpNames()[1])
}
func ExampleRegexp_Split() {
- a := regexp.MustCompile("a")
+ a := regexp.MustCompile(`a`)
fmt.Println(a.Split("banana", -1))
fmt.Println(a.Split("banana", 0))
fmt.Println(a.Split("banana", 1))
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", 0))
fmt.Println(zp.Split("pizza", 1))