Issue15537
Created on 2012-08-02 14:58 by dabrahams, last changed 2022-04-11 14:57 by admin. This issue is now closed.
| Messages (5) | |||
|---|---|---|---|
| msg167228 - (view) | Author: Dave Abrahams (dabrahams) | Date: 2012-08-02 14:58 | |
compare the output of
$ python -c "open('/tmp/tst','w').write(100*'x\n');import re;print len(re.split('\n(?=x)', open('/tmp/tst').read()))"
100
with
$ python -c "open('/tmp/tst','w').write(100*'x\n');import re;print len(re.split('\n(?=x)', open('/tmp/tst').read(), re.MULTILINE))"
9
|
|||
| msg167240 - (view) | Author: Serhiy Storchaka (serhiy.storchaka) * ![]() |
Date: 2012-08-02 17:05 | |
re.split = split(pattern, string, maxsplit=0, flags=0)
Split the source string by the occurrences of the pattern,
returning a list containing the resulting substrings. If
capturing parentheses are used in pattern, then the text of all
groups in the pattern are also returned as part of the resulting
list. If maxsplit is nonzero, at most maxsplit splits occur,
and the remainder of the string is returned as the final element
of the list.
maxsplit=0 in your fist example and maxsplit=8 (re.MULTILINE is 8) in your second example. This is not a bug, this is a wrong understanding.
|
|||
| msg167243 - (view) | Author: Matthew Barnett (mrabarnett) * ![]() |
Date: 2012-08-02 17:28 | |
There are actually 2 issues here: 1. The third argument is 'maxsplit', the fourth is 'flags'. 2. It never splits on a zero-width match. See issue 3262. |
|||
| msg167282 - (view) | Author: Ezio Melotti (ezio.melotti) * ![]() |
Date: 2012-08-03 02:41 | |
See also #11957. |
|||
| msg167283 - (view) | Author: Dave Abrahams (dabrahams) | Date: 2012-08-03 02:47 | |
Dang! Thanks, and sorry for wasting everyone's time on this. |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022-04-11 14:57:33 | admin | set | github: 59742 |
| 2014-10-29 16:13:16 | vstinner | set | superseder: re.sub confusion between count and flags args resolution: not a bug -> duplicate |
| 2012-08-04 21:07:14 | r.david.murray | link | issue15536 superseder |
| 2012-08-03 02:47:47 | dabrahams | set | messages: + msg167283 |
| 2012-08-03 02:41:48 | ezio.melotti | set | status: open -> closed type: behavior messages: + msg167282 resolution: not a bug |
| 2012-08-02 17:29:00 | mrabarnett | set | messages: + msg167243 |
| 2012-08-02 17:05:06 | serhiy.storchaka | set | nosy:
+ serhiy.storchaka messages: + msg167240 |
| 2012-08-02 14:58:56 | dabrahams | create | |

