diff --git a/src/regexp/example_test.go b/src/regexp/example_test.go index 466b38b0fa2..75202df0bad 100644 --- a/src/regexp/example_test.go +++ b/src/regexp/example_test.go @@ -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: