Lets say I have this data
data = '''a, b, c
d, e, f
g. h, i
j, k , l
'''
4th line contains one single space, 6th and 7th line does not contain any space, just a blank new line.
Now when I split the same using splitlines
data.splitlines()
I get
['a, b, c', 'd, e, f', 'g. h, i', ' ', 'j, k , l', '', '']
However expected was just
['a, b, c', 'd, e, f', 'g. h, i', 'j, k , l']
Is there a simple solution using regular expressions to do this.
Please note that I know the other way of doing the same by filtering empty strings from the output of splitlines()
I am not sure if the same can be achieved using regex.
When I use regex to split on new line, it gives me
import re
re.split("\n", data)
Output :
['a, b, c', 'd,e,f', 'g. h, i', ' ', 'j, k , l', '', '', '']