split on blank lines

Jan Burgy jburgy at hotmail.com
Mon Dec 1 09:10:57 EST 2003


Hi everyone,

can somebody tell me why (using Python 2.3.2)

>>> import re
>>> re.compile(r"^$", re.MULTILINE).split("foo\n\nbar\n\nbaz")
['foo\n\nbar\n\nbaz']

? Being used to Perl semantics, I expect

['foo\n', 'bar\n', 'baz']

or something equivalent without the '\n' characters in the result
strings. I have found that

>>> re.compile(r"^\n", re.MULTILINE).split("foo\n\nbar\n\nbaz")
['foo\n', 'bar\n', 'baz']

I prefer the first version however because my intent is stated more
clearly. Could this be a bug in sre.py (I looked at the code for a
good two minutes but then my head started hurting)

Thanks for your help,

Jan




More information about the Python-list mailing list