This issue tracker has been migrated to GitHub ,
and is currently read-only.
For more information,
see the GitHub FAQs in the Python's Developer Guide.
Created on 2014年10月29日 15:35 by mgdelmonte, last changed 2022年04月11日 14:58 by admin. This issue is now closed.
| Messages (5) | |||
|---|---|---|---|
| msg230216 - (view) | Author: Michael Del Monte (mgdelmonte) | Date: 2014年10月29日 15:35 | |
Easily reproduced:
re.sub('x', 'a', "x"*20, re.S)
returns 'aaaaaaaaaaaaaaaaxxxx'
|
|||
| msg230217 - (view) | Author: Peter Otten (peter.otten) * | Date: 2014年10月29日 15:49 | |
This is not a bug; the signature of re.sub() is
sub(pattern, repl, string, count=0, flags=0)
and the fourth argument thus the 'count' delimiting the number of substitutions that you accidentally specify as
>>> import re
>>> re.S
16
I recommend that you use a keyword arg to fix your code:
>>> re.sub('x', 'a', "x"*20, flags=re.S)
'aaaaaaaaaaaaaaaaaaaa'
|
|||
| msg230218 - (view) | Author: Georg Brandl (georg.brandl) * (Python committer) | Date: 2014年10月29日 15:51 | |
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. |
|||
| msg230219 - (view) | Author: STINNER Victor (vstinner) * (Python committer) | Date: 2014年10月29日 15:53 | |
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? |
|||
| msg230220 - (view) | Author: Ezio Melotti (ezio.melotti) * (Python committer) | Date: 2014年10月29日 15:54 | |
See #11957. |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022年04月11日 14:58:09 | admin | set | github: 66949 |
| 2014年10月29日 16:09:48 | vstinner | set | superseder: re.sub confusion between count and flags args resolution: not a bug -> duplicate |
| 2014年10月29日 15:54:28 | ezio.melotti | set | messages: + msg230220 |
| 2014年10月29日 15:53:06 | vstinner | set | nosy:
+ vstinner messages: + msg230219 |
| 2014年10月29日 15:51:11 | georg.brandl | set | status: open -> closed nosy: + georg.brandl messages: + msg230218 resolution: not a bug |
| 2014年10月29日 15:49:42 | peter.otten | set | nosy:
+ peter.otten messages: + msg230217 |
| 2014年10月29日 15:37:22 | pitrou | set | nosy:
+ serhiy.storchaka |
| 2014年10月29日 15:35:07 | mgdelmonte | create | |