CKTIS / Python
Module re
Compile regular expressions to search, match, extract or replace text.
Version: Python 3.14; repository image, production runtime not attested
Syntax
pattern = re.compile(expression)Compile regular expressions to search, match, extract or replace text.
search scans for a match while fullmatch requires the entire string to match. A Unicode str pattern uses Unicode character classes by default, and the ASCII flag restricts classes such as digit.
A failed match returns None.
Examples
import re
p = re.compile(r"(?P<code>[A-Z]+)-(?P<n>\d+)")
text = "x AB-٣!"
m = p.search(text)
print(m.group("code"), m.group("n"), m.span())
print(p.fullmatch(text) is None, re.search(r"\d", "٣", re.ASCII) is None)
Result
AB ٣ (2, 6) True True
A failed match returns None.