-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Zero length regular expression match misbehaviour #2565
Comments
Okay, having looked at f_match, in particular this handling for zero-width matches and the loop termination condition, I see some issues. Here's another test case:
This outputs:
But it should output:
|
Hmmm, oniguruma doesn't make this easy. There doesn't seem to be any way to call I wonder if you would get the right result if you called it with the callback and filtered out every match that overlaps with the previously replaced match. |
This seems very thorny. It might be worth reviewing what other users of oniguruma do to implement this. It doesn't even seem like there's universal agreement between regex engines, especially with awkward cases like |
Please note that Case 2 in the original post has been resolved by 83f375c :
Note also that in this repaired version of jq, the following is nevertheless incorrect:
|
Description
Some regular expressions behave weirdly when matches are zero length - they miss matches or match too often.
Reproduction
Case 1
Input:
Output:
Expected:
There should be a match at the end of the string too.
Case 2
Input:
Output:
Expected:
The same match shouldn't show up twice. (Extra matches seem to be returned in number equal to the length of the string, for some reason. But they're all the same match at the same offset.)
Environment
Additional context
I stumbled on this trying to fix #2148 and found that my attempted solution didn't behave like I expected it to. I tried to isolate the problem and ended up with these.
The text was updated successfully, but these errors were encountered: