On this page
re.fullmatch
Prev: re.finditer | Up: re | Next: re.match
Rel: re.compile, re.error, re.escape, re.findall
Ref: docs.python.org — re.fullmatch
Tags: #public #python3 #stdlib #re
Import
import re
from re import fullmatch
Signature & Overview
re.fullmatch(pattern, string, flags=0)
Try to apply the pattern to all of the string, returning a Match object, or None if no match was found.
Usage
import re
assert re.fullmatch(r"\d{4}", "2026") is not None
assert re.fullmatch(r"\d{4}", "2026-extra") is None
Gotchas
- Cleaner than
^...$: Anchors both start and end of the entire string—especially useful because$matches before a trailing newline, whereasfullmatch()rejects trailing newlines unless matched explicitly. - Returns
MatchorNone: Always test truthiness before accessing.group().
REPL Inspect
from re import fullmatch
help(fullmatch)
Linked from
Related notes
- tuts/python3/stdlib_module/re/finditer Linked here; links to this page; shared tags: #re, #stdlib
- tuts/python3/stdlib_module/re/match Linked here; links to this page; shared tags: #re, #stdlib
- tuts/python3/stdlib_module/re Linked here; links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/re/compile Linked here; shared tags: #re, #stdlib
- tuts/python3/stdlib_module/re/error Linked here; shared tags: #re, #stdlib
- tuts/python3/stdlib_module/re/escape Linked here; shared tags: #re, #stdlib
- tuts/python3/stdlib_module/re/findall Linked here; shared tags: #re, #stdlib
- tuts/python3/stdlib_module/re/Match_class shared tags: #re, #stdlib
- tuts/python3/stdlib_module/re/Pattern shared tags: #re, #stdlib
- tuts/python3/stdlib_module/re/PatternError shared tags: #re, #stdlib