re
Regular expressions for Python strings (and bytes). The engine is
backtracking with sophisticated lookarounds, named groups, and
Unicode-aware classes.
Source-of-record: Lib/re/, Modules/_sre/,
re docs.
Top-level functions
| Function | Returns |
|---|---|
compile(pattern, flags=0) | Pattern object. |
search(pattern, string, flags=0) | First match or None. |
match(pattern, string, flags=0) | Match at start or None. |
fullmatch(pattern, string, flags=0) | Entire-string match. |
split(pattern, string, maxsplit=0, flags=0) | Split on matches. |
findall(pattern, string, flags=0) | All matches as strings or tuples. |
finditer(pattern, string, flags=0) | Iterator of Match. |
sub(pattern, repl, string, count=0, flags=0) | Substitute. |
subn(pattern, repl, string, count=0, flags=0) | (new_string, count). |
escape(string) | Backslash-escape regex specials. |
purge() | Clear the compile cache. |
Flags
| Flag | Effect |
|---|---|
IGNORECASE / I | Case-insensitive matching. |
MULTILINE / M | ^ and $ match at every line. |
DOTALL / S | . matches newlines too. |
VERBOSE / X | Ignore whitespace and # comments in pattern. |
ASCII / A | \\w, \\d, etc. match ASCII only. |
UNICODE / U | Unicode (default for str patterns). |
LOCALE / L | Locale-aware (bytes only). |
DEBUG | Print the compiled program. |
NOFLAG | 0. |