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

Return which regex pattern was successful #2603

Closed
Akash-Mair opened this issue Aug 30, 2023 · 1 comment
Closed

Return which regex pattern was successful #2603

Akash-Mair opened this issue Aug 30, 2023 · 1 comment

Comments

@Akash-Mair
Copy link

Hey!

I have a lot of regex patterns I'd like to apply on a file, this leds to something like:

rg --json --regexp <pattern> --regexp <pattern> .... <path>

This works great returning a bunch of matches but in the match json there is no way to identify which regex pattern/s led to the match.

If there is a way to do this already could you let me know and I'll close this issue.

Thanks so much :)

@BurntSushi
Copy link
Owner

Duplicate of #2471.

The good news is that the changes to the regex crate I talked about in #2471 have landed and you can now write a Rust program to search for multiple regexes simultaneously in a way that will tell you which matched. I should caution you though that it isn't magic and it can't scale to arbitrarily many regexes. But I have no plans to add this functionality to ripgrep at present.

Another technique is to use a crate like aho-corasick to do some part of the matching for you because it scales better.

But I'll stop here. If you want to talk more about the regex engine, we should move it to here: https://github.com/rust-lang/regex/discussions

@BurntSushi BurntSushi closed this as not planned Won't fix, can't repro, duplicate, stale Aug 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants