> -----Original Message----- > From: [EMAIL PROTECTED] [mailto:python- > [EMAIL PROTECTED] On Behalf Of > [EMAIL PROTECTED] > Sent: Tuesday, July 01, 2008 2:29 AM > To: python-list@python.org > Subject: How make regex that means "contains regex#1 but NOT regex#2" > ?? > > I'm looking over the docs for the re module and can't find how to > "NOT" an entire regex. > > For example..... > > How make regex that means "contains regex#1 but NOT regex#2" ? >
Match 'foo.*bar', except when 'not' appears between foo and bar. import re s = 'fooAAABBBbar' print "Should match:", s m = re.match(r'(foo(.(?!not))*bar)', s); if m: print m.groups() print s = 'fooAAAnotBBBbar' print "Should not match:", s m = re.match(r'(foo(.(?!not))*bar)', s); if m: print m.groups() == Output == Should match: fooAAABBBbar ('fooAAABBBbar', 'B') Should not match: fooAAAnotBBBbar ***** The information transmitted is intended only for the person or entity to which it is addressed and may contain confidential, proprietary, and/or privileged material. Any review, retransmission, dissemination or other use of, or taking of any action in reliance upon this information by persons or entities other than the intended recipient is prohibited. If you received this in error, please contact the sender and delete the material from all computers. GA621 -- http://mail.python.org/mailman/listinfo/python-list