]> Cypherpunks.ru repositories - gostls13.git/commitdiff
regexp: add ReplaceAllStringFunc example
authorValentin Vidic <vvidic@valentin-vidic.from.hr>
Wed, 27 Feb 2019 20:20:58 +0000 (20:20 +0000)
committerIan Lance Taylor <iant@golang.org>
Wed, 27 Feb 2019 21:48:41 +0000 (21:48 +0000)
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 <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
src/regexp/example_test.go

index 3008c56b6bea94799e0c5c5a4043f338ee8ae832..a44c9396dedf4cb654622e570adeb6187fcb5beb 100644 (file)
@@ -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"))