CKTIS / Python
Regular expressions
A pattern describes text structure and fullmatch requires the entire string to match.
Version: Python 3.14; repository image, production runtime not attested
Syntax
match = re.fullmatch(r'([A-Z]+)-([0-9]+)', text)A pattern describes text structure and fullmatch requires the entire string to match.
search can find a substring. Capturing groups return text without conversion. The range [0-9] limits digits to ASCII, while \d in a str pattern normally also matches other Unicode decimal digits.
QA-07 yields ('QA', '07'), preserving the zero. A prefix and a fullwidth digit each produce None.
import re
p=re.compile(r'(?P<team>[A-Z]+)-(?P<number>[0-9]+)')
m=p.search('id QA-07!')
assert m.group('number')=='07' and m.span()==(3,8)
assert p.fullmatch('id QA-07!') is None
assert re.fullmatch(r'\d','7') and not re.fullmatch(r'[0-9]','7')
Examples
import re
pattern = re.compile(r"(?P<team>[A-Z]+)-(?P<number>[0-9]+)")
for text in ["QA-07", "prefix QA-07", "QA-7"]:
match = pattern.fullmatch(text)
print(match.groups() if match else None)
Result
('QA', '07')
None
NoneQA-07 yields ('QA', '07'), preserving the zero. A prefix and a fullwidth digit each produce None.