Skip to content
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/syntax: (?:A) doesn't compile #64668

Closed
dolmen opened this issue Dec 12, 2023 · 2 comments
Closed

regexp/syntax: (?:A) doesn't compile #64668

dolmen opened this issue Dec 12, 2023 · 2 comments
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.

Comments

@dolmen
Copy link
Contributor

dolmen commented Dec 12, 2023

Go version

go version go1.21.5 darwin/arm64

What operating system and processor architecture are you using (go env)?

N/A

What did you do?

From regexp/syntax:

(?:re)         non-capturing group

https://go.dev/play/p/YKM2yyDC2Bm

import "regexp/syntax"

fmt.Println(syntax.Parse("(?:A)", 0))

Output:

<nil> error parsing regexp: missing argument to repetition operator: `?`
$ perl -E 'say ("A" =~ /(?:A)/)'
1
$ go run github.com/dolmen-go/goeval@latest -i=regexp/syntax -i=fmt 'fmt.Println(syntax.Parse("(A)", 0))'
(A) <nil>
$ go run github.com/dolmen-go/goeval@latest -i=regexp/syntax -i=fmt 'fmt.Println(syntax.Parse("(?:A)", 0))'  
<nil> error parsing regexp: missing argument to repetition operator: `?`

What did you expect to see?

no error

What did you see instead?

Output:

<nil> error parsing regexp: missing argument to repetition operator: `?`
@mauri870 mauri870 added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Dec 12, 2023
@Jorropo
Copy link
Member

Jorropo commented Dec 12, 2023

Doing this works:

import "regexp/syntax"

fmt.Println(syntax.Parse("(?:A)", syntax.Perl))

(this is what regexp.Compile uses)

0 is posix syntax:

POSIX Flags = 0 // POSIX syntax

Which does not have support for non capturing groups as far as I checked.

There is this text which attempts to explain this.
https://pkg.go.dev/regexp/syntax#hdr-Syntax

I guess each feature could explain under which syntax it is supposed to work. In a table form it might even be digest.

@dolmen
Copy link
Contributor Author

dolmen commented Dec 12, 2023

OK, closing. I will see instead about submitting documentation improvements.

@dolmen dolmen closed this as completed Dec 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

3 participants