Split string with multiple delimiters in Python [duplicate]

Luckily, Python has this built-in 🙂

import re
re.split('; |, ',str)

Update:
Following your comment:

>>> a='Beautiful, is; better*than\nugly'
>>> import re
>>> re.split('; |, |\*|\n',a)
['Beautiful', 'is', 'better', 'than', 'ugly']

Leave a Comment