diff options
Diffstat (limited to 'libgo/go/regexp/example_test.go')
-rw-r--r-- | libgo/go/regexp/example_test.go | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/libgo/go/regexp/example_test.go b/libgo/go/regexp/example_test.go index ea35a2e5918..466b38b0fa2 100644 --- a/libgo/go/regexp/example_test.go +++ b/libgo/go/regexp/example_test.go @@ -280,6 +280,19 @@ func ExampleRegexp_SubexpNames() { // Turing Alan } +func ExampleRegexp_SubexpIndex() { + re := regexp.MustCompile(`(?P<first>[a-zA-Z]+) (?P<last>[a-zA-Z]+)`) + fmt.Println(re.MatchString("Alan Turing")) + matches := re.FindStringSubmatch("Alan Turing") + lastIndex := re.SubexpIndex("last") + fmt.Printf("last => %d\n", lastIndex) + fmt.Println(matches[lastIndex]) + // Output: + // true + // last => 2 + // Turing +} + func ExampleRegexp_Split() { a := regexp.MustCompile(`a`) fmt.Println(a.Split("banana", -1)) |