Regex matching and extraction
Learn in depth →Regular expressions recognize text patterns; fullmatch checks the entire input.
re.search(pattern, text); re.fullmatch(pattern, text)Example
import re
print(bool(re.fullmatch(r"[A-Z]{2}[0-9]{3}", "AB123")))
print(re.findall(r"[0-9]+", "a12 b7"))Result
True ['12', '7']
Watch for: search can match a substring. Avoid ambiguous nested repetition with untrusted inputs; a match is not domain validation.
Practise this topic →