Sometimes, we want to split string with multiple delimiters in Python.
In this article, we’ll look at how to split string with multiple delimiters in Python.
How to split string with multiple delimiters in Python?
To split string with multiple delimiters in Python, we can use the re.split
method.
For instance, we write
import re
a = 'Quick, brown; fox jumped*over\na dog'
re.split('; |, |\*|\n', a)
to call re.split
with a string with the list of symbols we want to split by and the a
string to split the string by the symbols listed.
Conclusion
To split string with multiple delimiters in Python, we can use the re.split
method.