-
-
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
Show capturing groups in --json
mode
#2325
Comments
Related #1872 Could you please provide an end-to-end use case where you'd want this? My suspicion is that it isn't necessary. The other issue here is that resolving capturing groups can be slow, so it would need to be behind a flag, i.e., |
Thank you for your help! Like you suspected, I actually did find a solution (without the My use case was the following: The solution I now have is I stumbled upon the |
I'd like to consider re-opening this issue, since I have a use case for it! If we could somehow provide capturing groups in the JSON output (don't mind if it's gated behind a flag or something) then it would enable using I suppose the only way I could work around this, is if I used |
@acheronfail Is it possible for you to just re-run the regex on the matched lines to get capture groups? |
@BurntSushi that is a possible workaround, yes. In fact, it does seem like this is the strategy that VSCode uses:
So, my program doesn't depend on any regular expression functionality right now, so including a regex crate and using that to match on the lines would definitely be a solution to the issue. I can't imagine it would be that hard, perhaps the only thing is detecting whether a regular expression with groups was passed... I imagine a regex crate would be able to tell me this in some way. In terms of a performance trade off - I don't think it would be that bad. Since I only need to perform the regular expression matches on visible lines ( The main bottleneck in performance in Long story short: @BurntSushi I think it makes sense for |
I would like to reopen the issue since I also have a use case for it. I'm using nushell to parse strings into structured data, but I want to use rg for the actual regex. The parsing requires the capture groups numbers & names, as well as what they actually capture to structure the data (each capture group number/name represent a column & each row is a match). Having a Additionally |
I couldn't find any way to show capturing groups in
--json
mode.Motivation:
Sometimes I'm interested in a group. After parsing the json, I need to filter the group in an additional step. Possibly with the same regex as in the first step. In such cases it would be nice if this was directly supported.
Example how this feature could look like:
echo 'Hello! !World! !foo!' | rg --json '!(\w+?)!' | jq
The text was updated successfully, but these errors were encountered: