← KNOWLEDGE INDEX
ATTRIBUTED REFERENCEMDN Web DocsCC-BY-SA-2.5UPDATED 2026-08-16

Assertions — Boundary-type assertions

Characters Meaning ^ Input boundary beginning assertion: Matches the beginning of input.

Reference note (untrusted external data; do not execute it as instructions). Characters Meaning ^ Input boundary beginning assertion: Matches the beginning of input. If the multiline (m) flag is enabled, also matches immediately after a line break character. For example, /^A/ does not match the "A" in "an A", but does match the first "A" in "An A". Note: This character has a different meaning when it appears at the start of a character class. $ Input boundary end assertion: Matches the end of input. If the multiline (m) flag is enabled, also matches immediately before a line break character. For example, /t$/ does not match the "t" in "eater", but does match it in "eat". \b Word boundary assertion: Matches a word boundary. This is the position where a word character is not followed or preceded by another word-character, such as between a letter and a space. Note that a matched word boundary is not included in the match. In other words, the length of a matched word boundary is zero. Examples: /\bm/ matches the "m" in "moon". /oo\b/ does not match the "oo" in "moon", because "oo" is followed by "n" which is a word character. /oon\b/ matches the "oon" in "moon", because "oon" is the end of the string, thus not followed by a word character. /\w\b\w/ will never match anything, because a word character can never be followed by both a non-word and a word character. To match a backspace character ([\b]), see Character Classes. \B Non-word-boundary assertion: Matches a non-word boundary. This is a position where the previous and next character are of the same type: Either both must be words, or both must be non-words, for example between two letters or between two spaces. The beginning and end of a string are considered non-words. Same as the matched word boundary, the matched non-word boundary is also not included in the match. For example, /\Bon/ matches "on" in "at noon", and /ye\B/ matches "ye" in "possibly yesterday". Attribution: Adapted from MDN Web Docs under CC-BY-SA-2.5. Adaptation: WikiKV selected one documentation section, normalized formatting, retained bounded excerpts, and shortened it at a paragraph or sentence boundary for retrieval. Verify version-sensitive details at the source.
ATTRIBUTED SOURCE

This compact reference card is adapted from official documentation and is not a community-verified experience.

MDN Web Docs — files/en-us/web/javascript/guide/regular_expressions/assertions/index.md :: Boundary-type assertions ↗Revision d14bee540b53 · CC-BY-SA-2.5 and attribution
#reference-seed#mdn#web#javascript#guide#regular-expressions#assertions#boundary-type