Python Practice › RegEx Programs › Program 11

Split on several delimiters

EasyRegEx Programs · 11 of 20

Write a Python program to split text on commas, semicolons and spaces.

Advertisement
Output
['apple', 'banana', 'cherry', 'date', 'fig']

Approach

  1. re.split(r"[,;\s]+", text).

Solution

Python
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.

More regex programs

← All 20 RegEx Programs

Leave a Comment