mirror of
https://github.com/golang/go
synced 2024-11-25 09:07:58 -07:00
regexp: add comment in example test describing tricky behavior
This commit is contained in:
parent
0fd7be7ee5
commit
1e7b236f3f
@ -226,6 +226,7 @@ func ExampleRegexp_ReplaceAll() {
|
||||
re := regexp.MustCompile(`a(x*)b`)
|
||||
fmt.Printf("%s\n", re.ReplaceAll([]byte("-ab-axxb-"), []byte("T")))
|
||||
fmt.Printf("%s\n", re.ReplaceAll([]byte("-ab-axxb-"), []byte("$1")))
|
||||
// Tries to find the named group `$1W` which is not present, so empty.
|
||||
fmt.Printf("%s\n", re.ReplaceAll([]byte("-ab-axxb-"), []byte("$1W")))
|
||||
fmt.Printf("%s\n", re.ReplaceAll([]byte("-ab-axxb-"), []byte("${1}W")))
|
||||
// Output:
|
||||
@ -250,6 +251,7 @@ func ExampleRegexp_ReplaceAllString() {
|
||||
re := regexp.MustCompile(`a(x*)b`)
|
||||
fmt.Println(re.ReplaceAllString("-ab-axxb-", "T"))
|
||||
fmt.Println(re.ReplaceAllString("-ab-axxb-", "$1"))
|
||||
// Tries to find the named group `$1W` which is not present, so empty.
|
||||
fmt.Println(re.ReplaceAllString("-ab-axxb-", "$1W"))
|
||||
fmt.Println(re.ReplaceAllString("-ab-axxb-", "${1}W"))
|
||||
// Output:
|
||||
|
Loading…
Reference in New Issue
Block a user