On Aug 16, 1:07 am, Steven D'Aprano <st...@remove-this-
cybersource.com.au> wrote:
> You're passing re.IGNORECASE (which happens to equal 2) as a count
> argument, not as a flag. Try this instead:
>
> >>> re.sub(r"python\d\d" + '(?i)', "Python27", t)
> 'Python27'

Basically right, but in-line flags must be placed at the start of a
pattern, or the result is undefined. Also in Python 2.7 re.sub() has a
flags argument.

Python 2.7.0+ (release27-maint:83286, Aug 16 2010, 01:25:58)
[GCC 4.4.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import re
>>> t = 'Python26'
>>> re.sub(r'(?i)python\d\d', 'Python27', t)
'Python27'
>>> re.sub(r'python\d\d', 'Python27', t, flags=re.IGNORECASE)
'Python27'

Alex
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to