-
-
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
Output only matched patterns (data extraction) #320
Comments
It's a missing feature: #34. It's on my list of things to do soon, but it's part of a larger refactoring effort, so it might take a little longer. There is a work around today though. You can use the
I think that should do it. (On mobile so i haven't checked.) |
Not really. Replacing works as intended apparently, in this case:
But the thing is, the actual output is still unchanged, because the program always returns the whole line where the match was found. To help illustrate things better, I made an example file: https://fnpaste.com/YZvd But I found a way around this: Changing the rx syntax to match the whole line, and then replace the whole line with capture group 1. For example: This gives me the desired part. But there is a big caveat: I use the I tried I'm not really familiar with the intricacies of regular expressions in Rust, so this needs a bit of tweaking, I guess, although it should definitely be possible. |
You're right. I forgot to add that you need to make your regex match the entire line in order for I think this gives the desired output for you though:
The trick is to make the |
Thanks! That did the trick just fine, greedy vs. lazy, obviously.. I'll close this issue for now. |
Is there some easy syntax to output only certain but several capture group indexes? Let's say with pcregrep there is a way to do this:
Which will produce:
I suppose that --replace method with capturing the whole line would help, but something easier would be useful. |
Sure:
|
If you have more questions, please use Discussions instead of burying them in old issues. :) |
Hi,
just been trying ripgrep for the first time, but I couldn't find an easy and straightforward way to just output the matching pattern.
For example, trying to search in a file like this:
rg "(\{.*\}\})" example.txt
The regex matching works as intended, correct result is highlighted in bold red text.
But when I tried to redirect ("pipe") the output to another program I realized that the actual output is still the unchanged input.
Am I missing something here? I couldn't find an option just for this output, seemed pretty straightforward to me, but neither
rg --help
or the front page here seem to mention something..The text was updated successfully, but these errors were encountered: