Case insensitive re.sub()

Aahz Maruch aahz at
Wed Feb 21 01:13:44 CET 2001

In article <mailman.982712484.28722.python-list at>,
Timothy Grant  <tjg at> wrote:
>I am working on a little project where it would be really nice
>to be able to do a case insensitive re.sub(). It appears that
>re.sub() does not allow a flags argument. Is it possible, or do
>I have to roll my own?

import re
regex = re.compile('foo', re.I)
print regex.sub('bar','FOOBAR')
                      --- Aahz (Copyright 2001 by aahz at

Androgynous poly kinky vanilla queer het    <*>
Hugs and backrubs -- I break Rule 6

The problem with an ever-changing .sig is that you have to keep changing it

More information about the Python-list mailing list