Python Practice › RegEx Programs › Program 11
Split on several delimiters
Write a Python program to split text on commas, semicolons and spaces.
Output
['apple', 'banana', 'cherry', 'date', 'fig']
Approach
re.split(r"[,;\s]+", text).
Solution
import re print(re.split(r"[,;\s]+", "apple, banana;cherry date,fig"))Output
['apple', 'banana', 'cherry', 'date', 'fig']
Learn the concept
New to this topic? Read the lesson, then come back.