-
Notifications
You must be signed in to change notification settings - Fork 160
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: (|a)* matches more text than (|a)+ does #136
Comments
The final Go fix is here: https://go-review.googlesource.com/c/go/+/318750/4/src/regexp/syntax/compile.go. |
Thank you, I'll port the fix to RE2/J shortly. |
sjamesr
added a commit
to sjamesr/re2j
that referenced
this issue
May 27, 2021
Original go fix: golang/go@2a61b3c Change description from that commit: In Perl mode, (|a)* should match an empty string at the start of the input. Instead it matches as many a's as possible. Because (|a)+ is handled correctly, matching only an empty string, this leads to the paradox that e* can match more text than e+ (for e = (|a)) and that e+ is sometimes different from ee*. The current code treats e* and e+ as the same structure, with different entry points. In the case of e* the preference list ends up not quite in the right order, in part because the "before e" and "after e" states are the same state. Splitting them apart fixes the preference list, and that can be done by compiling e* as if it were (e+)?. Fixes google#136.
sjamesr
added a commit
to sjamesr/re2j
that referenced
this issue
May 27, 2021
Ports fix of golang/go#46123 to RE2/J. Original go fix: golang/go@2a61b3c Change description from that commit: In Perl mode, (|a)* should match an empty string at the start of the input. Instead it matches as many a's as possible. Because (|a)+ is handled correctly, matching only an empty string, this leads to the paradox that e* can match more text than e+ (for e = (|a)) and that e+ is sometimes different from ee*. The current code treats e* and e+ as the same structure, with different entry points. In the case of e* the preference list ends up not quite in the right order, in part because the "before e" and "after e" states are the same state. Splitting them apart fixes the preference list, and that can be done by compiling e* as if it were (e+)?. Fixes google#136.
sjamesr
added a commit
to sjamesr/re2j
that referenced
this issue
May 27, 2021
Ports fix of golang/go#46123 to RE2/J. Original go fix: golang/go@2a61b3c Change description from that commit: In Perl mode, (|a)* should match an empty string at the start of the input. Instead it matches as many a's as possible. Because (|a)+ is handled correctly, matching only an empty string, this leads to the paradox that e* can match more text than e+ (for e = (|a)) and that e+ is sometimes different from ee*. The current code treats e* and e+ as the same structure, with different entry points. In the case of e* the preference list ends up not quite in the right order, in part because the "before e" and "after e" states are the same state. Splitting them apart fixes the preference list, and that can be done by compiling e* as if it were (e+)?. Fixes google#136.
sjamesr
added a commit
to sjamesr/re2j
that referenced
this issue
May 27, 2021
Ports fix of golang/go#46123 to RE2/J. Original go fix: golang/go@2a61b3c Change description from that commit: In Perl mode, (|a)* should match an empty string at the start of the input. Instead it matches as many a's as possible. Because (|a)+ is handled correctly, matching only an empty string, this leads to the paradox that e* can match more text than e+ (for e = (|a)) and that e+ is sometimes different from ee*. The current code treats e* and e+ as the same structure, with different entry points. In the case of e* the preference list ends up not quite in the right order, in part because the "before e" and "after e" states are the same state. Splitting them apart fixes the preference list, and that can be done by compiling e* as if it were (e+)?. Fixes google#136.
sjamesr
added a commit
that referenced
this issue
May 28, 2021
Ports fix of golang/go#46123 to RE2/J. Original go fix: golang/go@2a61b3c Change description from that commit: In Perl mode, (|a)* should match an empty string at the start of the input. Instead it matches as many a's as possible. Because (|a)+ is handled correctly, matching only an empty string, this leads to the paradox that e* can match more text than e+ (for e = (|a)) and that e+ is sometimes different from ee*. The current code treats e* and e+ as the same structure, with different entry points. In the case of e* the preference list ends up not quite in the right order, in part because the "before e" and "after e" states are the same state. Splitting them apart fixes the preference list, and that can be done by compiling e* as if it were (e+)?. Fixes #136.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
From golang/go#46123 (the Go implementation of the algorithm):
@BurntSushi noticed that in Rust regex (rust-lang/regex#779):
The text was updated successfully, but these errors were encountered: