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.

classification
Title: re.split doesn't respect MULTILINE
Type: behavior Stage: resolved
Components: Regular Expressions Versions: Python 2.7
process
Status: closed Resolution: duplicate
Dependencies: Superseder: MULTILINE confuses re.split
View: 15537
Assigned To: Nosy List: dabrahams, ezio.melotti, mrabarnett, serhiy.storchaka
Priority: normal Keywords:

Created on 2012-08-02 14:41 by dabrahams, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (2)
msg167224 - (view) Author: Dave Abrahams (dabrahams) Date: 2012-08-02 14:41
This session demonstrates. See especially the very last expression evaluated

>>> s='''this is the end
s='''this is the end
... your only friend
your only friend
... the end'''
the end'''
>>> re.split('^', s, re.MULTILINE)
re.split('^', s, re.MULTILINE)
['this is the end\nyour only friend\nthe end']
>>> re.split('t', s, re.MULTILINE)
re.split('t', s, re.MULTILINE)
['', 'his is ', 'he end\nyour only friend\n', 'he end']
>>> re.split('\n', s, re.MULTILINE)
re.split('\n', s, re.MULTILINE)
['this is the end', 'your only friend', 'the end']
>>> re.split('(?<=\n)', s, re.MULTILINE)
re.split('(?<=\n)', s, re.MULTILINE)
['this is the end\nyour only friend\nthe end']
>>> re.split('^y', s, re.MULTILINE)
re.split('^y', s, re.MULTILINE)
['this is the end\nyour only friend\nthe end']
>>> re.split('$', s, re.MULTILINE)
re.split('$', s, re.MULTILINE)
['this is the end\nyour only friend\nthe end']
>>> re.split('$\n', s, re.MULTILINE)
re.split('$\n', s, re.MULTILINE)
['this is the end\nyour only friend\nthe end']
>>> re.split('\n', s, re.MULTILINE)
re.split('\n', s, re.MULTILINE)
['this is the end', 'your only friend', 'the end']
>>> re.split('^t', s, re.MULTILINE)
re.split('^t', s, re.MULTILINE)
['', 'his is the end\nyour only friend\nthe end']
>>> re.split('^t', s)
re.split('^t', s)
['', 'his is the end\nyour only friend\nthe end']
>>>
msg167241 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2012-08-02 17:06
Same as for issue 15537.
History
Date User Action Args
2022-04-11 14:57:33adminsetgithub: 59741
2012-08-04 21:07:14r.david.murraysetstatus: open -> closed
superseder: MULTILINE confuses re.split
resolution: duplicate
stage: resolved
2012-08-02 17:06:50serhiy.storchakasetnosy: + serhiy.storchaka
messages: + msg167241
2012-08-02 14:41:18dabrahamscreate