MEPX
Chapter 4 of 10All chapters

Chapter 4 of 10

Anchors and boundaries

Matching positions.

Start and end

A caret anchors to the start and a dollar to the end. With the multiline flag they anchor to each line rather than the whole string.

  • Anchoring a validation pattern at both ends is what stops a partial match passing.
  • A caret means start outside brackets and not inside them.

Word boundaries

The escape \b matches a position between a word character and a non-word character. It is why \bcat\b matches cat but not category.