Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / Python

re.fullmatch

Requires the regular expression to consume the entire string.

Version: Python 3.14; repository image, production runtime not attested

Syntax

re.fullmatch(pattern, string, flags=0)

Requires the regular expression to consume the entire string.

A valid prefix alone fails when extra characters remain, making this operation suitable for whole-field validation.

For a field validator the match must cover the complete input. Return a Match on success and None otherwise; a successful empty match still has a truthy Match object. The uppercase-letter pattern requires exactly two letters, accepting AB and rejecting the longer AB3 even though its prefix fits.

import re
assert re.fullmatch("[A-Z]{2}", "AB").span() == (0, 2)
assert re.fullmatch("[A-Z]{2}", "AB\n") is None
m = re.fullmatch("a*", "")
assert m and m.span() == (0, 0)

Examples

import re
print(bool(re.fullmatch(r"[A-Z]{2}", "AB")))
print(re.fullmatch(r"[A-Z]{2}", "AB3"))

Result

True
None

For a field validator the match must cover the complete input. Return a Match on success and None otherwise; a successful empty match still has a truthy Match object. The uppercase-letter pattern requires exactly two letters, accepting AB and rejecting the longer AB3 even though its prefix fits.

Sources