I'm doing
delimiters = [r'\r\n', r'\.\.\.', r'\W']
pattern = regex.compile(r'(' + r'|'.join(delimiters) + r')', flags=regex.V1)
pattern.split(s)
to split s on multiple delimiters (using parentheses to retain delimiters in the output).
How can I prevent splitting on white space when it occurs alone? For example,
'abc, def , geh,, , ijk lmn \n opq'
should give
`['abc', ', ', 'def', ' , ', 'geh', ',, , ', 'ijk lmn', ' \n ', 'opq']
That is, when white space occurs together with another delimiter, the split should be performed but not when it there is only white space between the tokens. By white space I really only mean white space ' ', not any other tokens such as line break.s
(These are actually two questions, as right now I'm getting ['abc', ',', '', ' ', 'def', ' ', 'geh'], that is, multiple delimiters come out separately, while I would like them to come out aggregated.)