Use the built-in split method to split strings with multiple delimiters in Python. Just pass multiple delimiters with space into a method.
import re re.split('; |, ',str)
Example Split string with multiple delimiters in Python
Simple example code. Where delimiter is a sequence of one or more characters used to specify the boundary between separate, independent regions in plain text or other data streams. An example of a delimiter is the comma character.
import re s = 'Beautiful, is; better*than\nugly' res = re.split('; |, |\*|\n', s) print(res)
import re text = 'The quick brown\nfox jumps*over the lazy dog.' print(re.split('; |, |\*|\n',text))
Output: [‘The quick brown’, ‘fox jumps’, ‘over the lazy dog.’]
Do comment if you have any doubts and suggestions on this Python split topic.
Note: IDE: PyCharm 2021.1.3 (Community Edition)
All Python Examples are in Python 3, so Maybe its different from python 2 or upgraded versions.
Degree in Computer Science and Engineer: App Developer and has multiple Programming languages experience. Enthusiasm for technology & like learning technical.