Skip to content
AldeaCode Logo
Regex Tester / JavaScript Developer 100% local

Regex tester for JavaScript: the JS flavor, sticky y, and Unicode v

JavaScript regex is its own dialect. It looks like PCRE on the surface, but the differences trip people up: no possessive quantifiers, no recursion, sticky y has subtle scan rules, and the v flag added genuinely new set operations in 2023.

What the JS flavor has

Modern JavaScript regex covers most of what you actually need. Lookahead and lookbehind are both supported in V8, JavaScriptCore, and SpiderMonkey, including variable-length lookbehind. Older Safari builds before 16.4 lacked lookbehind, so if your audience still includes a long tail of iOS devices on older OS versions, feature-detect or polyfill.

Named capture groups landed in ES2018: (?\d{4}). The match result exposes them on match.groups. Backreferences to named groups use \k, and replace strings reference them as $.

What the JS flavor lacks

Three holes worth knowing.

No recursion. PCRE supports (?R) for recursive subroutines; JavaScript does not. Patterns that need to match arbitrarily nested brackets cannot be written as a single JS regex. Use a parser.

No possessive quantifiers. PCRE has a*+ to prevent backtracking; JavaScript does not. The workaround is (?=(a*))\1 using lookahead and a backreference, but the readability cost is real, so consider a different approach.

No conditional groups, no atomic groups. Both exist in PCRE. Both can usually be reshaped into alternations with care.

Flags that matter: y, u, v

Sticky y anchors the match at lastIndex and only there. Combined with exec in a loop, it lets you tokenise input efficiently without backtracking through earlier characters. Different from g: g searches forward from lastIndex; y requires an exact start.

Unicode u enables proper code-point handling. Without it, . matches one UTF-16 code unit, splitting astral characters like emoji in half. With it, \p{Letter} and other Unicode property escapes work.

Unicode sets v (ES2024) is a superset of u. It adds set operations: intersection &&, subtraction --, and string-literal sets [\q{ab|cd}]. Use it when you want to express "letter that is not Greek" or "any of these multi-character sequences".

match, matchAll, replaceAll with named groups

String.prototype.match returns the first match (or all when the regex has g). matchAll returns an iterator of full match objects, including capture groups, which is what you usually want. replaceAll with a regex requires the g flag or it throws. The example below extracts ISO dates, replaces them with a different format using named group references, and lists every match for inspection.

Working example

javascript
const text = "Released 2024-03-15 and 2025-01-08, audit on 2026-05-10.";

const isoDate = /(?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2})/g;

// Iterate every match with named groups
for (const m of text.matchAll(isoDate)) {
  const { year, month, day } = m.groups;
  console.log(`${day}/${month}/${year}`);
}

// Replace using named back-references
const reformatted = text.replaceAll(isoDate, "$<day>/$<month>/$<year>");
console.log(reformatted);

// Sticky flag for tokenising
const tokeniser = /\s*(\w+)/y;
tokeniser.lastIndex = 0;
const first = tokeniser.exec("hello world");
console.log(first[1]); // "hello"

Just need the result?

When you are sketching a regex for a JS project and want to see exactly what it captures before pasting into code, the regex tester on aldeacode.com runs the pattern in the same engine the browser uses. Toggle u and v flags, name your groups, see the match objects update live. No round trip through a server, no surprises when the regex hits production.

Open Regex Tester (JavaScript Flavor) →

Frequently asked questions

Should I always use the u flag?

Yes for any pattern touching user-supplied text. Without u, astral characters break in half and Unicode property escapes do not work. The cost is negligible and the correctness gain is real.

When should I prefer v over u?

When you need set operations or string-literal sets. v is a strict superset, so existing u patterns work under v unchanged unless they relied on edge-case behaviour. Browser support landed across all engines in 2023 to 2024.

What is the difference between g and y in a loop?

g advances lastIndex past the match and continues searching forward. y requires the next match to start exactly at lastIndex. y is what you want when tokenising a known grammar, g is what you want when scanning prose for occurrences.