regular expression negate a word (not character)

Ilya Zakharevich nospam-abuse at ilyaz.org
Sat Jan 26 16:39:02 EST 2008


[A complimentary Cc of this posting was sent to
Summercool 
<Summercoolness at gmail.com>], who wrote in article <27249159-9ff3-4887-acb7-99cf0d2582a8 at n20g2000hsh.googlegroups.com>:
> so for example, it will grep for
> 
>   winter tire
>   tire
>   retire
>   tired
> 
> but will not grep for
> 
>   snow tire
>   snow   tire
>   some snowtires

This does not describe the problem completely.  What about

  thisnow tire
  snow; tire

etc?  Anyway, one of the obvious modifications of

   (^ | \b(?!snow) \w+ ) \W* tire

should work.

Hope this helps,
Ilya




More information about the Python-list mailing list