You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
re.sub replaces only first 32 matches with re.U flag #55471
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
assignee=Noneclosed_at=<Date2011-02-20.23:01:03.740>created_at=<Date2011-02-20.22:28:09.731>labels= ['type-security', 'expert-regex', 'invalid']
title='re.sub replaces only first 32 matches with re.U flag'updated_at=<Date2011-02-20.23:01:03.731>user='https://bugs.python.org/EugeneMorozov'
There's a peculiar and difficult to find bug in the re.sub method. Try following example:
>>> text ='X'*4096
>>> nt = re.sub(u"XX", u".", text, re.U)
>>> nt
u'............XXXXXXXXXXXXXXXXXXX' (only 32 dots, the rest of the string is not changed).
If I first compile regexp, and then perform compiled_regexp.sub, everything seems to work correctly.
Activity
EugeneMorozov commentedon Feb 20, 2011
If I first compile regexp, and then perform compiled_regexp.sub, everything seems to work correctly.
SilentGhost commentedon Feb 20, 2011
If you read docs carefully, you notice that re.sub doesn't accept flags argument. Its 4th argument is count, re.U numerical value is 32.
Closing as invalid. There are some duplicates too, I'm sure.