Reading — step 1 of 5
Read
~1 min readQuantifiers & Anchors
Anchors: ^ $ \b
Anchors match positions, not characters:
| Anchor | Matches |
|---|---|
^ | start of string (or start of line in m mode) |
$ | end of string (or end of line in m mode) |
\b | word boundary (between \w and non-\w) |
\B | NOT a word boundary |
\A | absolute start of input (no multiline override) |
\Z | absolute end of input |
Implementation: anchors don't consume text — they just check the position.
python
Common anchored patterns:
^\d+$— entire string is a number\bword\b— whole-word match^//— line starting with//(in multiline mode)\.$— ends with a dot
Multiline mode (re.M in Python, m flag in JS): ^ and $ match at
every \n, not just at string boundaries.
Discussion
Ask a question, share an insight, or help someone who’s stuck.
Sign in to post a comment or reply.
Loading…