From: Paul McGuire Date: 2008-01-29T06:39:59+09:00 Subject: Re: regular expression negate a word (not character) On Jan 25, 7:16 pm, Summercool wrote: > somebody who is a regular expression guru... how do you negate a word > and grep for all words that is > >   tire > > but not > >   snow tire > > or > >   snowtire > Too bad pyparsing's not an option. Here's what it would look like: data = """ Match: > winter tire > tire > retire > tired But not match: > snow tire > snow tire > some snowtires snowbird tire tired on a snow day snow tire and regular tire """ from pyparsing import CaselessLiteral,Literal,line # caseless wasn't really necessary but you never know # when you'll run into a "Snow tire" snow = CaselessLiteral("snow") tire = Literal("tire") tire.ignore(snow + tire) for matchTokens,matchStart,matchEnd in tire.scanString(data): print line(matchStart, data) Prints: > winter tire > tire > retire > tired snowbird tire tired on a snow day snow tire and regular tire -- Paul