Regex Anchors and Boundaries

Pin patterns to string, line, and word edges.

  • regex anchor
  • word boundary
  • multiline flag
  • match whole string
  • caret dollar

Regex Anchors and Boundaries

Pin patterns to string, line, and word edges.

Commands

CommandWhat it does
^abcStart of string or line
xyz$End of string or line
\bword\bWhole word only
\BNot a word boundary
^...$ with m flagPer-line anchors

Example

\berror\b  # matches error, not errors

FAQ

How do caret and dollar behave with multiline?

Without the m flag they anchor the whole string; with m they anchor each line.

How do I match a whole input exactly?

Wrap as start-group-end so partial matches cannot slip through validation.

자주 묻는 질문

How do caret and dollar behave with multiline?
Without the m flag they anchor the whole string; with m they anchor each line.
How do I match a whole input exactly?
Wrap as start-group-end so partial matches cannot slip through validation.

Regex