Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.Sign up
regexp: Expand rules are confusing #40329
What version of Go are you using (
I think the simplest change is to nudge people to use the more explicit syntax.
A lot of the time, people don't look at the examples in the docs, they just look at the text that pops up in their development environment, so how about this?
The problem with skipping the braces when referring to submatches is hinted at in the example code, but it's a bit too subtle, maybe adding a comment there would bring it to the attention. I don't think any more than that is needed.
// $1W is not a named submatch, so the replacement is with an empty slice. fmt.Printf("%s\n", re.ReplaceAll(byte("-ab-axxb-"), byte("$1W")))