Precise? The OP asked for "tokens". #>>> re.search(r"(and|or|xor)\s*#", "a = the_operand # gotcha!") #<_sre.SRE_Match object at 0x00AE6620>
Try this: #>>> re.search(r"\b(and|or|xor)\s*#", "a = the_operand # should fail") #>>> re.search(r"\b(and|or|xor)\s*#", "and # OK") #<_sre.SRE_Match object at 0x00AE6E60> #>>> re.search(r"\b(and|or|xor)\s*#", "blah blah and # OK") #<_sre.SRE_Match object at 0x00AE66E0> -- http://mail.python.org/mailman/listinfo/python-list