I have a line that I am trying to break into pieces on empty lines.
Given the string s , I thought I could do this:
re.split('(?m)^\s*$', s)
This works in some cases:
>>> s = 'foo\nbar\n \nbaz' >>> re.split('(?m)^\s*$', s) ['foo\nbar\n', '\nbaz']
But this does not work if the line is completely empty:
>>> s = 'foo\nbar\n\nbaz' >>> re.split('(?m)^\s*$', s) ['foo\nbar\n\nbaz']
What am I doing wrong?
[python 2.5; it makes no difference if I compile '^\s*$' with re.MULTILINE and use the compiled expression instead]
python regex
John fouhy
source share