-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
rg outputs wrong matches when everything is matched and replaced with custom string #1739
Comments
I think this is because of how $ echo 'a' | rg '.*' -r '$0.<NO_EXTENSION>'
a.<NO_EXTENSION>
.<NO_EXTENSION>
$ echo 'a' | rg '.+' -r '$0.<NO_EXTENSION>'
a.<NO_EXTENSION>
$ echo 'a' | perl -lpe 's/.*/$&.<NO_EXTENSION>/g'
a.<NO_EXTENSION>.<NO_EXTENSION>
$ echo 'a' | perl -lpe 's/.+/$&.<NO_EXTENSION>/g'
a.<NO_EXTENSION> See https://www.regular-expressions.info/zerolength.html for a detailed discussion on this topic. |
The
My guess here is that something about the replacement code is erroneously matching the position immediately after the Moreover, it is at least inconsistent:
Notice how the second search reports exactly one match. Which is inconsistent with the fact that the replacement behaves as if there are two matches. So as far as I can tell, one of these is wrong. |
Just remembered, I had filed a similar issue: #1295 |
What version of ripgrep are you using?
ripgrep 12.1.1
-SIMD -AVX (compiled)
+SIMD +AVX (runtime)
How did you install ripgrep?
brew install ripgrep
What operating system are you using ripgrep on?
Darwin 19.6.0 x86_64
zsh 5.8 (x86_64-apple-darwin19.6.0)
Describe your bug.
rg outputs wrong matches when everything is matched and replaced with custom string
What are the steps to reproduce the behavior?
Preparation
Example1 - When it works
Example2 - When it fails
What is the expected behavior?
Example2 - How it should behave
What do you think ripgrep should have done?
Removed the .<NO_EXTENSION> from the output
The text was updated successfully, but these errors were encountered: