Source Code:
(back to article)
import re # The string to split s = "foo,bar:baz;qux" # The delimiters to split on delimiters = ",:;" # Create a regular expression pattern from the delimiters pattern = "|".join(map(re.escape, delimiters)) # Split the string using the pattern result = re.split(pattern, s) print(result) # Output: ['foo', 'bar', 'baz', 'qux']
Result:
Report an issue