I'm having trouble splitting a text file using empty line "\n\n" delimiters.
re.split("\n", aString)
works but
re.split("\n\n", aString)
just returns the whole string.
Any ideas?
Beware the line ending conventions of different operating systems!
\r\n)\n)\r)You are probably failing because the double newline you are looking for is in a Windows-encoded text file, and will appear as \r\n\r\n, not \n\n.
The repr() function will tell you for sure what your line endings are:
>>> mystring = #[[a line of your file]]
>>> repr(mystring)
"'\\nmulti\\nline\\nstring '"
Are you sure that you don't just want to read the file line by line in the first place?
with open(file.txt, 'r') as f:
for line in f:
print (line)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With