On this page
  1. re.split
  2. Import
  3. Signature & Overview
  4. Usage
  5. Gotchas
  6. REPL Inspect

re.split

Prev: re.search | Up: re | Next: re.sub
Rel: re.compile, re.error, re.escape, re.findall
Ref: docs.python.org — re.split
Tags: #public #python3 #stdlib #re


Import

import re
from re import split

Signature & Overview

re.split(pattern, string, maxsplit=0, flags=0)

Split the source string by the occurrences of the pattern, returning a list containing the resulting substrings. If capturing parentheses are used in pattern, then the text of all

Usage

import re

assert re.split(r"[,;\s]+", "a, b; c  d") == ["a", "b", "c", "d"]
assert re.split(r"[,;]+", "a,b;c", maxsplit=1) == ["a", "b;c"]

Gotchas

REPL Inspect

from re import split
help(split)

Linked from

Related notes