Regex Explainer

What \b matches

Word boundaries are positions, not characters, which is why they behave oddly at the edges of a string.

/\bcat\b/

Match a word boundary, then "c", then "a", then "t", then a word boundary.

What to check

  • Probably a bug

    Unanchored — matches anywhere in the input

    Without ^ and $ the pattern succeeds if it matches ANY substring. A validator meant to check a whole value will therefore accept anything that merely contains a valid value: an email pattern without anchors accepts "nonsense a@b.co nonsense".

    Fix: Wrap the pattern in ^ and $ if it is validating a whole string. Leave it unanchored only if you are genuinely searching within text.

Step by step

  1. \b

    Anchor to a word boundary.

  2. c

    Match "c".

  3. a

    Match "a".

  4. t

    Match "t".

  5. \b

    Anchor to a word boundary.

Details

Capture groups
None
Flags
None set

Check your own pattern

Paste one on the home page, or call the API or MCP server. This page is also available as markdown.

Related examples