string split in python multiple separators code example

Example 1: multi split python

str = 'Lorem; ipsum. dolor sit amet, consectetur adipiscing elit.'
str = str.split(',')
print(str) # Output ['Lorem; ipsum. dolor sit amet', ' consectetur adipiscing elit.']

import re
str = 'Lorem; ipsum. dolor sit amet, consectetur adipiscing elit.'
str = re.split(r';|,|\.', str)
print(str) # Output ['Lorem', ' ipsum', ' dolor sit amet', ' consectetur adipiscing elit', '']

Example 2: how to split a string in python with multiple delimiters

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

Example 3: python split multiple delimiters

#Do a str.replace('? ', ', ') and then a str.split(', ')
#Example:
a = "Hello, what is your name? I'm Bob."
a.replace('? ', ', ')
print(a)
#"Hello, what is your name, I'm Bob."
a.split(", ")
print(a)
#["Hello", "what is your name", "I'm Bob."]