Avian’s Blog

Electronics and Free Software

Python regex trap

17.04.2008 19:09

This simple Python one liner will not do what you expect:

>>> import re
>>> re.sub("the", "", "The Last Lecture", re.I)

Before someone again accuses me of being illiterate: Yes, this behavior is documented. It's still one of those things that go undetected for a long time and bite you in the most inappropriate time. It's right up there with C's "if(x=0) ..." on the annoyance scale.

Posted by Tomaž | Categories: Code
Comments
Add a new comment

Your name

Your email (optional)

Your web site (optional)


(No HTML tags allowed. Separate paragraphs with a blank line.)