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

No match highlighting when using pcre2 #2484

Closed
fabian-thomas opened this issue Apr 3, 2023 · 5 comments
Closed

No match highlighting when using pcre2 #2484

fabian-thomas opened this issue Apr 3, 2023 · 5 comments
Labels
invalid An issue that is not actually a bug or a feature that already exists.

Comments

@fabian-thomas
Copy link

What version of ripgrep are you using?

ripgrep 13.0.0
-SIMD -AVX (compiled)
+SIMD +AVX (runtime)

How did you install ripgrep?

Arch repositories

What operating system are you using ripgrep on?

Arch linux, all packages latest

Describe your bug.

When using the pcre2 regex engine, rg does not highlight matches.

What are the steps to reproduce the behavior?

rg -p -P -e "^(?=.*one)"

with a file with content:

one

I would assume this to highlight the matched word one, as rg would do without the -P flag.

@BurntSushi
Copy link
Owner

Your regex only matches the empty string, so no highlighting is correct.

Look around only controls whether something matches. The whole point of it is that it doesn't change the offsets of the match. In other words, you're asking for something that is directly contrary to the feature you're using.

@BurntSushi BurntSushi closed this as not planned Won't fix, can't repro, duplicate, stale Apr 4, 2023
@BurntSushi BurntSushi added the invalid An issue that is not actually a bug or a feature that already exists. label Apr 4, 2023
@fabian-thomas
Copy link
Author

Thanks for the explanation! Makes sense. So there is absolutely no way to get what I want with one ripgrep call?
Note that the real pattern I want to search for is something like this: rg -P -e "^(?=.*one)(?=.*three)". So basically match all lines that have both one and three, and I would want highlighting for all occurences of one and three.

What I could do I guess, is to pipe the results through ripgrep one more time and then highlight all occurences of one and three.

@BurntSushi
Copy link
Owner

What I could do I guess, is to pipe the results through ripgrep one more time and then highlight all occurences of one and three.

Yes. This is the way for now. There is also a ticket for adding more sophisticated boolean matching that would probably let you achieve your objective here. On mobile, or otherwise I would link it.

@fabian-thomas
Copy link
Author

For future reference:
#875 is the issue about boolean matching.
I'm just mentioning here that ugrep might be the tool you are searching if you arive at this issue. It supports matching against multiple patterns combined with an and. The command for that is ugrep --and one --and three.

@BurntSushi
Copy link
Owner

git grep supports it too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
invalid An issue that is not actually a bug or a feature that already exists.
Projects
None yet
Development

No branches or pull requests

2 participants