Case insensitive re.sub()

Alex Martelli aleaxit at yahoo.com
Wed Feb 21 04:34:59 EST 2001


"Timothy Grant" <tjg at exceptionalminds.com> wrote in message
news:mailman.982712484.28722.python-list at python.org...
> Hi all,
>
> 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?

Python 2.0 (#8, Oct 16 2000, 17:27:58) [MSC 32 bit (Intel)] on win32
Type "copyright", "credits" or "license" for more information.
>>> import re
>>> cre=re.compile('pip',re.IGNORECASE)
>>> cre.sub("A pip and a PIPpop", 'plup')
'plup'
>>> cre.sub('plup', "A pip and a PIPpop")
'A plup and a pluppop'
>>>


Alex






More information about the Python-list mailing list