How we can break a string with multiple delimiters in Python?

PythonServer Side ProgrammingProgramming

We can break a string with multiple delimiters using the re.split(delimiter, str) method. It takes a regex of delimiters and the string we need to split. For example:

a='Beautiful, is; better*than
ugly' import re print(re.split('; |, |\*|
',a))

We get the output

['Beautiful', 'is', 'better', 'than', 'ugly']
raja
Updated on 30-Sep-2019 06:49:24

Advertisements