[Tutor] re.sub() query

Evert Rol evert.rol at gmail.com
Sun Jun 20 12:03:47 CEST 2010

> Is it possible to solve the below, w/o making a re object?
>>>> a
> 'Mary Had a Little Lamb'
>>>> p=re.compile('l',re.I)
>>>> re.sub(p,'-',a)
> 'Mary Had a -itt-e -amb'
> I cannot figure how to se re.I w/o involving  p.

Would this work?
>>> re.sub('(?i)l', '-', a)

See http://docs.python.org/library/re.html#regular-expression-syntax , search for iLmsux, which provide flags inside the regex.

More information about the Tutor mailing list