Pin the match to a position
Anchors are zero-width — they don't consume characters, they just assert that you're at a specific position.
^— start of string (or start of line, with the MULTILINE flag)$— end of string (or end of line, with MULTILINE)
Without anchors, your pattern can match anywhere. With ^pattern$, you're saying "the entire input is exactly this pattern."
The MULTILINE flag
By default, ^ and $ match the start and end of the whole string. With re.MULTILINE (Python) or the m flag (PCRE/JS), they additionally match at the start and end of every line. This matters for processing multi-line input — log files, multi-line user input, etc.
The fullmatch alternative
In Python, re.fullmatch(pat, text) is shorthand for re.match(r"^" + pat + r"$", text). Use it when you want to validate that the entire string matches a pattern. It's clearer than wrapping anchors and harder to mess up.
The \A and \Z anchors
Some flavors (Python, PCRE, .NET) provide \A and \Z as absolute string-start and string-end. They ignore MULTILINE. So \A always means "start of input," never "start of line." Useful when you want anchoring that doesn't change with flags.