Split By Multiple Delimiters Python

Python

How to break a string with multiple delimiters in python?

1
Answers

Replies

It is possible to break the string with multiple delimiters by using the re.split(delimiter, str) method. It takes the regex of the delimiters and the strings that is required to be split


a='Beautiful, is; better*than\nugly'


import re


print(re.split('; |, |\*|\n',a))

 
 

If you want to unleash your potential in this competitive field, please visit the Python course page for more information, where you can find the Python tutorials and Python frequently asked interview questions and answers as well.

 

This topic has been locked/unapproved. No replies allowed

Login to participate in this discussion.

Leave a reply

Before proceeding, please check your email for a verification link. If you did not receive the email, click here to request another.
Protected by Astra Security