SyntaxStudy
Sign Up
Python Beginner 3 min read

re.split

re.split

re.split() splits a string at each regex match. Useful for splitting on variable whitespace or multiple delimiters.

Example
import re

text = "one, two;  three|four"
parts = re.split(r"[,;|\s]+", text)
print(parts)
# ["one", "two", "three", "four"]
Pro Tip

Capture groups in the pattern are included in the split result.