Lessons · Regex · a match that is not the whole value
A match that is not the whole value
A search that succeeds says the pattern OCCURS somewhere. It never says the value is that thing.
Hone is a place to practise programming. This is one of its lessons, written out in full and free to read without an account.
What it is for
It is how junk ends up stored in the same column as good data: the check passed, and it was answering a different question.
How to think about it
Validating means both ends nailed down. fullmatch, or \A and \Z, or ^ and $ if a trailing newline is acceptable.
Worked example
re.search(r'\d{4}-\d{2}-\d{2}', '2026-09-09xx').group()A date is in there, so search succeeds.re.fullmatch(r'\d{4}-\d{2}-\d{2}', '2026-09-09xx')But the value is not a date.re.match(r'[0-9]{3}', '123456789').group()And match only covers the front, so {3} lets the rest through.Your turn
Require three digits and nothing else, both ends.
\A\d{3}Test a pattern against real text
The trap
Two half-measures leave a hole: match covers the start, a fixed count stops counting, and nothing at all covers the end.
Practise a match that is not the whole value on HoneA question on it now, a coding challenge where there is one, and it is remembered for review. Free, no email needed.