Python 3: regex to split on successions of newline characters
Posted
by Beau Martínez
on Stack Overflow
See other posts from Stack Overflow
or by Beau Martínez
Published on 2010-04-08T00:20:56Z
Indexed on
2010/04/08
0:23 UTC
Read the original article
Hit count: 762
python-3.x
|regex
I'm trying to split a string on newline characters (catering for Windows, OS X, and Unix text file newline characters). If there are any succession of these, I want to split on that too and not include any in the result.
So, for when splitting the following:
"Foo\r\n\r\nDouble Windows\r\rDouble OS X\n\nDouble Unix\r\nWindows\rOS X\nUnix"
The result would be:
['Foo', 'Double Windows', 'Double OS X', 'Double Unix', 'Windows', 'OS X', 'Unix']
What regex should I use?
© Stack Overflow or respective owner