On Jan 25, 7:16*pm, Summercool <Summercooln...@gmail.comwrote:
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