ggreer / the_silver_searcher

A code-searching tool similar to ack, but faster.
http://geoff.greer.fm/ag/
Apache License 2.0
26.07k stars 1.42k forks source link

how to specify capturing group of regular expression ? #1475

Open beppe9000 opened 2 years ago

beppe9000 commented 2 years ago

let's say i want to print an url from a stream. I would use a regex like this cat requrest.txt | ag "location: (https\:\/\/www\.example\.com\/.*\n)" but I don't know how to make it print only the capture group (which is the url, without the location part.)

brunetton commented 2 years ago

Exactly what I'm looking for. Any solution ?

Of course I could do:

ag "url: (.*)" -o --nofilename --nocolor |  grep -oP "http.*"

But this is not really satisfying

brunetton commented 2 years ago

For future reference, I'm now using RipGrep that allows group capturing and more