mirror of
https://github.com/golang/go
synced 2024-09-24 05:10:13 -06:00
regexp: add ReplaceAllStringFunc example
Change-Id: I016312f3ecf3dfcbf0eaf24e31b6842d80abb029
GitHub-Last-Rev: 360047c900
GitHub-Pull-Request: golang/go#30445
Reviewed-on: https://go-review.googlesource.com/c/164257
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
This commit is contained in:
parent
9f9c5fa8c7
commit
56f0c046cf
@ -7,6 +7,7 @@ package regexp_test
|
||||
import (
|
||||
"fmt"
|
||||
"regexp"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func Example() {
|
||||
@ -204,6 +205,13 @@ func ExampleRegexp_ReplaceAllString() {
|
||||
// -W-xxW-
|
||||
}
|
||||
|
||||
func ExampleRegexp_ReplaceAllStringFunc() {
|
||||
re := regexp.MustCompile(`[^aeiou]`)
|
||||
fmt.Println(re.ReplaceAllStringFunc("seafood fool", strings.ToUpper))
|
||||
// Output:
|
||||
// SeaFooD FooL
|
||||
}
|
||||
|
||||
func ExampleRegexp_SubexpNames() {
|
||||
re := regexp.MustCompile(`(?P<first>[a-zA-Z]+) (?P<last>[a-zA-Z]+)`)
|
||||
fmt.Println(re.MatchString("Alan Turing"))
|
||||
|
Loading…
Reference in New Issue
Block a user