[thelist] Reg Ex - everything except a phrase

Joshua Olson joshua at waetech.com
Thu Sep 11 08:29:36 CDT 2003

----- Original Message ----- 
From: "Elankath, Tarun (Cognizant)" <ETarun at blr.cognizant.com>
Sent: Thursday, September 11, 2003 3:36 AM

> How about the piece of Python code below (which uses negative lookahead) ?

> r = re.compile(r"^(?:(?!\bFred\b).)*$")

> Will this work for all cases ?


Nice regex... very smooth thinking.  However, it does match "Hello Fred" on
my test engine, and it should not.  I believe that is because word
boundaries do not always match with end of line depending on what platform
your testing on?

Good work.

Joshua Olson
Web Application Engineer
WAE Tech Inc.

More information about the thelist mailing list