Categories
Python Answers

How to split string with multiple delimiters in Python?

Spread the love

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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *