Dev Helpers

Python / Regular expressions

Split on multiple delimiters

Dev Helpers · July 6, 2025

A regular expression can describe a family of separators in one pass. Consecutive separators raise a separate question about empty fields.

Worked example

import re
print(re.split(r'[,;]+', 'red,green;blue'))

Result

['red', 'green', 'blue']

Implementation notes

A capturing group changes what re.split returns. Use a noncapturing group when only the fields, rather than the matched delimiters, belong in the result.

Try it yourself

Feed the parser a trailing delimiter and two different adjacent delimiters.

Open the Python example →

Editorial date July 6, 2025 · Published December 6, 2026

Related articles

Run an async function

An async function call creates a coroutine. A top-level runner supplies the event loop that executes it.

Transpose a matrix

Transposing rows into columns assumes a decision about uneven rows. Ordinary zip stops at the shortest input.

Unpack with a remainder

Starred unpacking separates a fixed header from a variable-length tail. It still requires enough elements for the fixed positions.