Input:
x = "121, 1238,\nxyz,\n 123abc \n\rabc123"
I want to split This string with the delimiters ",", "\n", "\r", "\s" to get the output
['121', '1238', 'xyz', '123abc', 'abc123']
Whatever I try, the delimiters are accepted as single characters and not as combination of characters. e.g.
1.
re.split("\n|,|\s|\r", x)
Gave output of
['121', '', '1238', '', 'xyz', '', '', '123abc', '', '', 'abc123']
re.split("\n\s|,|\s|\r", x)
Gave output of
['121', '', '1238', '', 'xyz', '', '123abc', '', 'abc123']
The second one is a slight improvement over the first one. But if that's what is required, I need to give all possible combinations manually.
something Like (with more combinations):
re.split("\n\s|\s\n|\s\n\s|\n|,\s|\s,|\s,\s|,|\s|\r", x)
output:
['121', '1238', 'xyz', '', '123abc', '', 'abc123']
Is there any better way to do this?