Answers for "how to split a string in python with multiple delimiters"

5

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', '']
Posted by: Guest on May-04-2020
9

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']
Posted by: Guest on June-09-2020
0

python split string keep delimiter

line = "<html><head>"
d = ">"
s =  [e+d for e in line.split(d) if e]
print(s)
#Output:
#["<html>", "<head>"]
Posted by: Guest on December-23-2020
-1

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."]
Posted by: Guest on March-15-2021

Code answers related to "how to split a string in python with multiple delimiters"

Python Answers by Framework

Browse Popular Code Answers by Language