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 does only first 16 replacements if re.S is used #66949
bpo-11957: re.sub confusion between count and flags args
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=<Date2014-10-29.15:51:11.671>created_at=<Date2014-10-29.15:35:07.080>labels= ['expert-regex', 'type-bug']
title='re.sub does only first 16 replacements if re.S is used'updated_at=<Date2014-10-29.16:09:48.499>user='https://bugs.python.org/mgdelmonte'
Activity
mgdelmonte commentedon Oct 29, 2014
Easily reproduced:
returns 'aaaaaaaaaaaaaaaaxxxx'
peterotten commentedon Oct 29, 2014
This is not a bug; the signature of re.sub() is
and the fourth argument thus the 'count' delimiting the number of substitutions that you accidentally specify as
>>> import re >>> re.S 16I recommend that you use a keyword arg to fix your code:
birkenfeld commentedon Oct 29, 2014
The fourth parameter is not "flags", but "count", the max. number of substitutions. "flags" is the fifth parameter, or give it as a keyword argument.
vstinner commentedon Oct 29, 2014
This bug report is common. An enhancement would be to make the count parameter a keyword only parameter. Would it break a lot of code?
ezio-melotti commentedon Oct 29, 2014
See bpo-11957.