Re: OT: simple regex question

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, 2007-04-23 at 12:44 +0200, Dario Lesca wrote:
> Il giorno lun, 23/04/2007 alle 11.05 +0100, Matt Davey ha scritto:
> > echo "aa bb cc dd" | perl -pe 'exit(!(/(?=.*bb)(?=.*aa)/));'
> 
> Ok for perl, but I must match the word 'aa' and (for example) 'bb',
> someone like this: /(\saa\s)&(\sbb\s)/ .....
> 
> Your example found also "aa xxbb cc dd" and is not what I want...

you can use \b to indicate a word boundary.  So, to exclude xxbb and
bbxx, you can do:

echo "aa bb cc dd" | perl -pe 'exit(!(/(?=.*\bbb\b)(?=.*\bdd\b)/));'
    && echo found

Note: to previous poster who reckoned it matched either word, that may
have been because my first snippet was looking for 'aa' and 'bb', not
'bb' and 'dd' as in the original posting.

Matt Davey		It takes one drink to get me drunk, but I can't 
mcdavey@xxxxxxxxxxxxxx 	     remember if it's the 13th or 14th -- George Burns


[Index of Archives]     [Current Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]     [Fedora Docs]

  Powered by Linux