Quantcast
Channel: Capturing Groups From a Grep RegEx - Stack Overflow
Viewing all articles
Browse latest Browse all 11

Answer by Stephen Quan for Capturing Groups From a Grep RegEx

$
0
0

I have been having great success at using regex with capture groups with perl, e.g.

for f in 123_abc_123.jpg 123_xyz_432.jpgdo    echo $f    echo $f | perl -ne 'if (/[0-9]+_([[a-z]+)_[0-9a-z]*/) { print $1 . "\n" }'done

Outputs:

123_abc_123.jpgabc123_xyz_432.jpgxyz

So the if-regex conditional in perl will filter out all non-matching lines at the same time, for those lines that do match, it will apply the capture group(s) which you can access with $1, $2, ... respectively,


Viewing all articles
Browse latest Browse all 11

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>