From: Valentin Vidic Date: Wed, 27 Feb 2019 20:20:58 +0000 (+0000) Subject: regexp: add ReplaceAllStringFunc example X-Git-Tag: go1.13beta1~1313 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=56f0c046cfe9019e30ad0d0f85ac974de394ebd7;p=gostls13.git regexp: add ReplaceAllStringFunc example Change-Id: I016312f3ecf3dfcbf0eaf24e31b6842d80abb029 GitHub-Last-Rev: 360047c9006dba643429c006f89d813d927999b3 GitHub-Pull-Request: golang/go#30445 Reviewed-on: https://go-review.googlesource.com/c/164257 Run-TryBot: Ian Lance Taylor TryBot-Result: Gobot Gobot Reviewed-by: Ian Lance Taylor --- diff --git a/src/regexp/example_test.go b/src/regexp/example_test.go index 3008c56b6b..a44c9396de 100644 --- a/src/regexp/example_test.go +++ b/src/regexp/example_test.go @@ -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[a-zA-Z]+) (?P[a-zA-Z]+)`) fmt.Println(re.MatchString("Alan Turing"))