split string with 2 delimiters python code example
Example 1: multi split python
str = 'Lorem; ipsum. dolor sit amet, consectetur adipiscing elit.'
str = str.split(',')
print(str)
import re
str = 'Lorem; ipsum. dolor sit amet, consectetur adipiscing elit.'
str = re.split(r';|,|\.', str)
print(str)
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 string keep delimiter
line = "<html><head>"
d = ">"
s = [e+d for e in line.split(d) if e]
print(s)