Skip to content
Anchors: ^ $ \b
step 1/5

Reading — step 1 of 5

Read

~1 min readQuantifiers & Anchors

Anchors: ^ $ \b

Anchors match positions, not characters:

AnchorMatches
^start of string (or start of line in m mode)
$end of string (or end of line in m mode)
\bword boundary (between \w and non-\w)
\BNOT a word boundary
\Aabsolute start of input (no multiline override)
\Zabsolute 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…