CKTIS / Python
re.fullmatch
Comprueba si el patrón cubre todo el campo y devuelve un objeto Match o None.
Versión: Python 3.14; repository image, production runtime not attested
Sintaxis
re.fullmatch(pattern, string, flags=0)Comprueba si el patrón cubre todo el campo y devuelve un objeto Match o None.
Una coincidencia vacía válida también da un objeto verdadero en contexto lógico. El patrón [A-Z]{2} exige exactamente dos mayúsculas ASCII.
AB pasa y el carácter adicional de AB3 hace que falle toda la comprobación.
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)
Ejemplos
import re
print(bool(re.fullmatch(r"[A-Z]{2}", "AB")))
print(re.fullmatch(r"[A-Z]{2}", "AB3"))
Resultado
True None
AB pasa y el carácter adicional de AB3 hace que falle toda la comprobación.