Skip to content

Anchors and boundaries

Lines, and the word boundary

What m moves, and what \b is actually defined as.

The m flag moves ^ and $ from the ends of the input to the ends of every line. Nothing else about the pattern changes — . still refuses to cross a line break, because that is the s flag's job and not this one's.

\b is a position where a word character meets something that is not one — where \w and \W sit next to each other, or where one of them sits against the end of the input. \B is every other position.

So \b inherits \w's definition, including the underscore. cat_alogue has no word boundary after cat, and cat-like does.

Matcher

Every claim on the left has a pattern under it. Press one and it runs here, against the same engine that grades a task.