Commit 56f0c046 authored by Valentin Vidic's avatar Valentin Vidic Committed by Ian Lance Taylor

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 <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: default avatarIan Lance Taylor <iant@golang.org>
parent 9f9c5fa8
...@@ -7,6 +7,7 @@ package regexp_test ...@@ -7,6 +7,7 @@ package regexp_test
import ( import (
"fmt" "fmt"
"regexp" "regexp"
"strings"
) )
func Example() { func Example() {
...@@ -204,6 +205,13 @@ func ExampleRegexp_ReplaceAllString() { ...@@ -204,6 +205,13 @@ func ExampleRegexp_ReplaceAllString() {
// -W-xxW- // -W-xxW-
} }
func ExampleRegexp_ReplaceAllStringFunc() {
re := regexp.MustCompile(`[^aeiou]`)
fmt.Println(re.ReplaceAllStringFunc("seafood fool", strings.ToUpper))
// Output:
// SeaFooD FooL
}
func ExampleRegexp_SubexpNames() { 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.Println(re.MatchString("Alan Turing"))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment