[wellylug] Regex, replace stuff in command line help...

David Antliff david.antliff at gmail.com
Thu Jun 29 11:51:42 NZST 2006



On Thu, 29 Jun 2006, Grant McLean wrote:
> An example may clarify:
>
>  $ echo '<img src="x.gif" border="0">' | \
>  > perl -nle '/src="(.*?)"/ && print $1'
>  x.gif
>
> Versus, without the ?
>
>  $ echo '<img src="x.gif" border="0">' | \
>  >  perl -nle '/src="(.*)"/ && print $1'
>  x.gif" border="0

Indeed, I am familiar with the non-greedy rule for ?. However, this 
example is not analogous to your prior regexp because it includes a 
suffix anchor (").

In your original suggestion:

   perl -nle '/profile\?u=(.*?)/ && print $1' *

There is nothing on the end to anchor the pattern, so in this case, (.*?) 
will match the empty string:


$ echo '<a href="url or relative link/profile?u=mangee">' | perl -nle 
'/profile\?u=(.*)/ && print "[$1]"'
[mangee">]


$ echo '<a href="url or relative link/profile?u=mangee">' | perl -nle 
'/profile\?u=(.*?)/ && print "[$1]"'
[]


-- 
David.




More information about the wellylug mailing list