bugl
bugl
HomeLearnPatternsSearch
HomeLearnPatternsSearch

Loading lesson path

Learn/JavaScript/Working with Data
JavaScript•Working with Data

Regular Expression Assertions

RegExp Assertions

Assertions matches

Boundaries and

Lookarounds

String Boundaries and Word Boundaries. Lookarounds: Lookaheads and Lookbehinds.

// Match beginning of string const pattern = /^W3Schools/;
// Match end of string const pattern = /W3Schools$/;

JavaScript Regex Assertions

Revised July 2025

Syntax

Name

Description

^

String boundary

Matches the beginning of a string

$

String boundary

Matches the end of a string

\b

Word boundary

Matches the beginning or end of a word \B

Word boundary

Matches NOT the beginning or end of a word (?=...)

Lookahead

Matches the subsequent string

(?!...)

Lookahead

Matches NOT the subsequent string

(?<=...)

Lookbehind

Matches the previous string

(?<!...)

Lookbehind

Matches NOT the previous string

Formula

RegExp ^ Metacharacter
The ^ metacharacter matches the beginning of a string.

Examples

Test if a string starts with W3Schools:

const pattern = /^W3Schools/;
let text = "W3Schools Tutorial";
let result = pattern.test(text); // true const pattern = /^W3Schools/;
let text = "Hello W3Schools";
let result = pattern.test(text); // false

RegExp $ Metacharacter The $ metacharacter matches the end of a string. Test if a string ends with W3Schools:

const pattern = /W3Schools$/;
let text = "Hello W3Schools";
let result = pattern.test(text); // true const pattern = /W3Schools$/;
let text = "W3Schools tutorial";
let result = pattern.test(text); // false

The \b Metacharacter The \b metacharacter matches the beginning of a word or the end of a word.

Previous

JavaScript Set Reference

Next

JavaScript BigInt