[Philadelphia-pm] Perl one liner, regex capture group problem

Walt Mankowski waltman at pobox.com
Fri Oct 28 08:43:50 PDT 2011


On Fri, Oct 28, 2011 at 11:14:56AM -0400, Kyle R. Burton wrote:
> > command: curl -so- http://www.wikihow.com/Make-Easy-Homemade-Biscuits|perl
> > -nE "say $1 if /src='(\S+(?:png|jpg))'/"
> > abbreviated output:
> 
> Stan,
> 
> You may just be hitting shell replacement since the expression is in
> double quotes - try backslashing the $1:
> 
> ... perl -nE "say \$1 if /src='(\S+(?:png|jpg))'/"

An alternative would be to enclose the perl in single quotes instead
of double quotes. Then you don't have to worry about backslashing the
$1, but you do need to backslash the single quotes:

  perl -nE 'say $1 if /src=\'(\S+(?:png|jpg))\'/'

But unfortunately if you're on Windows then you can't use single
quotes. so you'll need to use Kyle's solution.

Walt
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 190 bytes
Desc: Digital signature
URL: <http://mail.pm.org/pipermail/philadelphia-pm/attachments/20111028/ebbca02c/attachment.bin>


More information about the Philadelphia-pm mailing list