On Sun, 15 Aug 2010 16:45:49 -0700, Christopher wrote:

> I have the following problem:
>
>>>> t="Python26"
>>>> import re
>>>> re.sub(r"python\d\d", "Python27", t)
> 'Python26'
>>>> re.sub(r"python\d\d", "Python27", t, re.IGNORECASE)
> 'Python26'
>>>> re.sub(r"Python\d\d", "Python27", t, re.IGNORECASE)
> 'Python27'

> Is this a known bug?  Is it by design for some odd reason?


>>> help(re.sub)

Help on function sub in module re:

    sub(pattern, repl, string, count=0)
    ...


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'



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

Reply via email to