Skip to content

re

Built-in regular-expression helpers. Works without Shared Library research. Patterns use a linear-time safe regular expression subset: common patterns like \d+, [A-Z]+, .*, ^, $, groups (...), and alternation a|b are supported; backtracking-only features such as lookaround and pattern backreferences are not. Patterns are capped at 512 characters.

ConstantAliasEffect
re.IGNORECASEre.ICase-insensitive matching
re.MULTILINEre.M^ and $ also match line boundaries
re.DOTALLre.S. also matches newline characters

Combine flags with |.

Search anywhere in string for pattern. Returns a Match object, or None if there is no match.

Returns: Match or None

Match pattern at the start of string. Returns a Match object, or None if the start does not match.

Returns: Match or None

Match the whole string against pattern. Returns a Match object, or None if any part is left unmatched.

Returns: Match or None

Return all non-overlapping matches. With no capture groups, the result is a list of matched strings. With one capture group, the result is that group. With multiple capture groups, the result is tuples.

Returns: list

re.sub(pattern, repl, string, count=0, flags=0)

Section titled “re.sub(pattern, repl, string, count=0, flags=0)”

Replace matches of pattern in string with repl. count=0 replaces all matches; a positive count limits replacements. Replacement text supports numeric backreferences like \1 and \g<1>.

Returns: string

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

Section titled “re.split(pattern, string, maxsplit=0, flags=0)”

Split string wherever pattern matches. maxsplit=0 means no limit. Capturing groups are included in the output, matching Python’s re.split behavior.

Returns: list