-
-
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
support fancier regex features such as look-around and backreferences #188
Comments
Indeed it is, but it's not a "problem" per se, it's a conscious and explicit trade-off that I made. Notably, this is the very first paragraph of the
If you'd like to read more about this, please consult Russ Cox's excellent series on the matter (I'd also be happy to answer specific questions): https://swtch.com/~rsc/regexp/
Note that this isn't an unfettered win, it's a trade off. For example:
The Silver Searcher completely drops the second match because it's using a backtracking regex engine, which is required* for supporting arbitrary lookaround.
You can satisfy this particular use case relatively easily with * - Strictly speaking, there is some theory that supports it without backtracking, but I'm not aware of a practically fast implementation of it. (There is TRE and regex-tdfa, of which I have used neither, but I've never seen any compelling evidence that either was fast. Come to think of it, I don't actually know if regex-tdfa supports arbitrary lookaround.) |
Thank you for the detailed response. I'll keep This specific case would be pretty hard to do using pipes since I used it in my text editor. |
Note that this is mentioned in the anti-pitch, which I should add to the README. |
Hi, I just heard that your project was included into the latest version of VSCode for text searching. Just recently I was trying to do a RegEx with a negative lookbehind across our entire code base. I could not get it to work in VSCode, but it worked for me in Sublime Text. I'd prefer to stay in VSCode, and at first was very excited to hear that they added a better text search. But then saw this issue where negative lookahead was discussed. I'm not sure if my specific case could also be re-written with pipes. I was trying to find an instance of "IN" or 'IN' with double or single quotes, but not as in type="in" cause that was the most common occurrence and not related. I also wanted to find a way where it was followed by Indiana or India shortly after, but didn't find a regex way to do that. Can you maybe give some more info on how to use the pipes with some examples, or maybe add the lookahead and lookbehind options? |
No. |
Thanks, I guess that won't work in VSCode as is just on commandline. |
This commit updates the CHANGELOG to reflect all the work done to make libripgrep a reality. * Closes #162 (libripgrep) * Closes #176 (multiline search) * Closes #188 (opt-in PCRE2 support) * Closes #244 (JSON output) * Closes #416 (Windows CRLF support) * Closes #917 (trim prefix whitespace) * Closes #993 (add --null-data flag) * Closes #997 (--passthru works with --replace) * Fixes #2 (memory maps and context handling work) * Fixes #200 (ripgrep stops when pipe is closed) * Fixes #389 (more intuitive `-w/--word-regexp`) * Fixes #643 (detection of stdin on Windows is better) * Fixes #441, Fixes #690, Fixes #980 (empty matching lines are weird) * Fixes #764 (coalesce color escapes) * Fixes #922 (memory maps failing is no big deal) * Fixes #937 (color escapes no longer used for empty matches) * Fixes #940 (--passthru does not impact exit status) * Fixes #1013 (show runtime CPU features in --version output)
This commit updates the CHANGELOG to reflect all the work done to make libripgrep a reality. * Closes #162 (libripgrep) * Closes #176 (multiline search) * Closes #188 (opt-in PCRE2 support) * Closes #244 (JSON output) * Closes #416 (Windows CRLF support) * Closes #917 (trim prefix whitespace) * Closes #993 (add --null-data flag) * Closes #997 (--passthru works with --replace) * Fixes #2 (memory maps and context handling work) * Fixes #200 (ripgrep stops when pipe is closed) * Fixes #389 (more intuitive `-w/--word-regexp`) * Fixes #643 (detection of stdin on Windows is better) * Fixes #441, Fixes #690, Fixes #980 (empty matching lines are weird) * Fixes #764 (coalesce color escapes) * Fixes #922 (memory maps failing is no big deal) * Fixes #937 (color escapes no longer used for empty matches) * Fixes #940 (--passthru does not impact exit status) * Fixes #1013 (show runtime CPU features in --version output)
@BurntSushi
obviously the package maintainer of homebrew will have the same question as me... |
The build instructions are in the README.
…On Thu, Aug 23, 2018, 03:34 Timothee Cour ***@***.***> wrote:
@BurntSushi <https://github.com/BurntSushi>
how do I enable PCRE2 ?
rg --pcre2 gives: PCRE2 is not available in this build of ripgrep
-
NOTE: I've installed rg via brew install --HEAD ripgrep to get the
HEAD version of rg.
-
the ripgrep formula is here:
https://github.com/Homebrew/homebrew-core/blob/master/Formula/ripgrep.rb
-
the relevant line is probably here: system "cargo", "install",
"--root", prefix
How do I change this to support --pcre2 ?
-
i read this but not sure how to proceed:
https://github.com/BurntSushi/ripgrep/blob/master/FAQ.md#how-do-i-use-lookaround-andor-backreferences
If you installed ripgrep through a different means (like your system's
package manager), then please reach out to the maintainer of that package
to see whether it's possible to enable the PCRE2 feature
obviously the package maintainer of homebrew will have the same question
as me...
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#188 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAb34i2UI3pwvgaw5VjAdpUUveFPkZ7Uks5uTlshgaJpZM4KashK>
.
|
For Homebrew, technically, the simplest possible change is to replace this
with this
Which is consistent with the build instructions in the README. Note that you cannot do this with the current release, since only master has the Note that if you do this, ripgrep will, by default, attempt to link with the system version of PCRE2. So you either need to add PCRE2 itself as an optional dependency of the |
thanks,
works with NOTE: This option mentioned in readme ( |
That doesn't mean anything to me. How am I supposed to diagnose "did not work" and help you fix it? |
using https://github.com/timotheecour/homebrew-timutil/blob/master/ripgrep_temp.rb brew tap timotheecour/timutil
|
You need a nightly compiler. Ref #188
@timotheecour Ah yes, thank you. The README says:
I've updated the text to make it a little more clear: 1bb8b71 |
nvim-telescope/telescope-live-grep-args.nvimでagを使えるようにした。否定先読がrgでできなかったため。パイプ使えばいいっぽいけど、telescopeでできないと思う。 BurntSushi/ripgrep#188
One area that makes
ag
unable to be replaced byripgrep
is thatag
supports negative lookahead. For example:This would find all rows with "foo", but not with "bar" somewhere after that on the same line.
ripgrep
gives the following error message:I guess this is actually a problem in the
regex
crate, and I can open the same issue there if you wish.The text was updated successfully, but these errors were encountered: