You did not answer Alan's question, but I will assume that he is right, and you are interested in a negative statement. IOW - corresponds to "bar", but not to "barfoo". In this case, you can create your regular expression as follows:
myregex = re.compile('bar(?!foo)') for example, from the python console: >>> import re >>> myregex = re.compile('bar(?!foo)') >>> m = myregex.search('barfoo') >>> print m.group(0) <=== Error here because match failed Traceback (most recent call last): File "<stdin>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'group' >>> m = myregex.search('bar') >>> print m.group(0) <==== SUCCESS! bar
David source share