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

Grant McLean grant at mclean.net.nz
Fri Jun 30 09:04:58 NZST 2006


On Fri, 2006-06-30 at 07:25 +1200, Jo Booth wrote:
> On 29/06/2006, at 11:51 , David Antliff wrote:
> 
> > $ 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]"'
> > []
> 
> It seemed to work (and yes I added an anchor of \" at the end) - but  
> I realised that it only seems to be getting the usernames from the  
> first few lines (which have a user name on separate lines) - the last  
> part of each html has the user-names in one huge long line - it seem  
> to get the first one - but not the rest....

If you specify the 'g' (for global matches) option after the trailing
slash, then the captured bits from the match are returned as an array,
which you can then iterate through with foreach:

perl -nle 'print "[$_]" foreach (/profile\?u=(.*?)"/g)' filename.html

Cheers
Grant




More information about the wellylug mailing list