Regex in JavaScript: 2026 Edition
A modern look at JavaScript regex including named groups, lookbehind, and the v flag.
v flag.Named Capture Groups
``js
const m = '2026-04-30'.match(/(?`
Self-documenting and stable across regex edits.
Lookbehind
`js
'$100'.match(/(?<=\$)\d+/); // ['100']
`
Both positive (?<=) and negative (?
Unicode Property Escapes
`js
/\p{Script=Hangul}/u.test('νκΈ'); // true
/\p{Emoji}/u.test('π'); // true
`
Replaces hard-coded ranges with Unicode-aware semantics.
The v Flag
v (set notation, ES2024) enables set operations on character classes:
`js
/[\p{Script=Greek}--[\p{ASCII}]]/v // Greek minus ASCII
/[\p{Letter}&&\p{ASCII}]/v // ASCII letters
`
Perfect for filtering by script while excluding common subsets.
RegExp.escape (Stage 4 in 2026)
`js
const safe = RegExp.escape(userInput);
new RegExp(safe).test(text);
`
Finally β no more home-grown escape functions.
matchAll
`js
for (const m of text.matchAll(/(\w+):(\d+)/g)) {
console.log(m[1], m[2]);
}
`
Returns an iterator with all matches and their groups, including named groups.
Performance Trap
Catastrophic backtracking happens with patterns like (a+)+. Engines vary in their protection. Use /timeout` test runners or move to a regex-free approach (e.g., StringDecoder for line splitting).
For broader text manipulation see [text case conventions](/blog/text-case-conventions).