Loading lesson path
String Boundaries and Word Boundaries. Lookarounds: Lookaheads and Lookbehinds.
// Match beginning of string const pattern = /^W3Schools/;
// Match end of string const pattern = /W3Schools$/;^
$
\b
Matches the beginning or end of a word \B
Matches NOT the beginning or end of a word (?=...)
(?!...)
(?<=...)
(?<!...)
Formula
RegExp ^ Metacharacter
The ^ metacharacter matches the beginning of a string.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); // falseRegExp $ 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); // falseThe \b Metacharacter The \b metacharacter matches the beginning of a word or the end of a word.