ANCHORS & BOUNDARIES

Word boundaries

\b matches the edge of a word. Whole-word search, finally.

\b matches the position between a word character (\w) and a non-word character - or the text edge. It marks the edge of a word and consumes nothing. \bcat\b matches cat as a whole word, but skips the cat buried inside concatenate.

Because it consumes nothing, "cat." still matches \bcat\b: the boundary sits in the gap between the t and the dot, and the dot stays out of the match.

The mirror of \b is \B: a position that is NOT a word boundary. \Bcat\B matches cat only when it sits buried inside a longer word, like "concatenate". MDN: \b and \B.

PRACTICE - 2 DRILLS 0/2 DONE
DRILL 1/2

Match cat only as a whole word.

/ /
my cat sleeps
must match: "cat"
concatenate
must match nothing
the cat.
must match: "cat"
cats are not cat
must match: "cat"
DRILL 2/2- The word "is"

Match is only as a whole word - not inside this, his or crisis.

/ /
this is it
must match: "is"
is this a crisis
must match: "is"
island
must match nothing