Back to Blog
Regex2026-04-16

Regex in JavaScript: 2026 Edition

A modern look at JavaScript regex including named groups, lookbehind, and the v flag.

JavaScript regex was historically behind Perl and Python. ES2018-2024 closed the gap with Unicode, lookbehind, named groups, and the new v flag.

Named Capture Groups

``js const m = '2026-04-30'.match(/(?\d{4})-(?\d{2})-(?\d{2})/); m.groups.year; // '2026' `

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).