In Python, I’d like to split a string using a list of separators. The separators could be either commas or semicolons. Whitespace should be removed unless it is in the middle of non-whitespace, non-separator characters, in which case it should be preserved.
Test case 1: ABC,DEF123,GHI_JKL,MN OP
Test case 2: ABC;DEF123;GHI_JKL;MN OP
Test case 3: ABC ; DEF123,GHI_JKL ; MN OP
Sounds like a case for regular expressions, which is fine, but if it’s easier or cleaner to do it another way that would be even better.
Thanks!
This should be much faster than regex and you can pass a list of separators as you wanted:
How to use it:
Performance test:
And with a much longer input string: