ggreer / the_silver_searcher

A code-searching tool similar to ack, but faster.

Home Page:http://geoff.greer.fm/ag/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

how to specify capturing group of regular expression ?

beppe9000 opened this issue · comments

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.)

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

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