-
Notifications
You must be signed in to change notification settings - Fork 17.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
regexp: Documentation doesn't mention that (?<name>...) capturing group syntax isn't currently supported #64108
Comments
It should be noted that the new syntax does work with "Go dev branch" in the playground, which means that support is slated for 1.22. Unfortunately, even historical versions of the regexp docs simply link to https://github.com/google/re2/wiki/Syntax, so no matter what this can cause some confusion. Kind of seems like the RE2 spec needs to be versioned so that the regexp docs (and others) can refer to a particular one. |
Support for this I believe there are no plans to backport this. I think re2 is linked for cross reference, the supported syntax is listed by running go doc regexp/syntax, as mentioned in the docs. |
@mauri870 The regexp docs currently say
In other words, it claims that it accepts RE2 as described on that wiki page (which is no longer the case), and only suggests running In addition, I think the |
Yeah I agree, this link always point out to the latest wiki which might include features that are not available for older versions of Go. The proper approach would be to just mention go doc regexp/syntax, which is bundled with the toolchain. So this is about updating the documentation on tip. Given our policy for backports this will likely not be fixed for 1.21 and 1.20, but it is a nice to have from now on. |
@mauri870 Thanks for taking a look at this. Would it be possible to update the |
Backports are for critical issues with no workaround, and minor releases prioritize backwards compatibility as much as possible, per the wiki. If it doesn't seem critical and can be worked around a backport is not needed. You are more than welcome tho to send a patch that updates the docs for the current tip (future 1.22) |
Got it; looking at the wiki page you linked, "Important documentation-only changes [...] may also be included as well, but nothing more.", and this probably doesn't qualify as important. I'll look into sending a patch to update the docs for the current tip, though I can't commit to it. |
The regexp documention point to the google/re2 syntax page, which causes confusion since users expect feature parity with RE2, which might not be the case if you are using an older version of Go. In regexp/syntax/doc.go there is already an autogenerated syntax based on RE2 and we already link to that in the docs, so removing the external link does not result in any loss of information. Fixes golang#64108
Change https://go.dev/cl/547795 mentions this issue: |
I wonder if that comment in the code is still relevant: // DO NOT EDIT. This file is generated by mksyntaxgo from the RE2 distribution. |
I recall running mksyntaxgo a couple days ago and it produced an up-to-date file with no changes, so I think it is still relevant. |
The documentation for the
regexp
package doesn't mention that the(?<name>)
syntax for capturing groups isn't currently supported by Go. This syntax has been added to RE2, there's an accepted proposal to add it to Go (#58458), but that hasn't yet been implemented in Go. The RE2 wiki page on syntax mentions that this syntax is valid, but theregexp
package docs link to that page without mentioning that(?<name>)
is unsupported in Go.What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes; the Go playground link below reproduces it in Go 1.21.4.
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
https://go.dev/play/p/8Jtqu9zq8LZ - this is the example for
regexp.Regexp
'sSubexpIndex
method, modified to use?<first>
and?<last>
instead of?P<first>
and?P<last>
.What did you expect to see?
(the output from running the existing example)
What did you see instead?
The text was updated successfully, but these errors were encountered: