2026-08-28
How JavaScript regular expressions actually match
A regular expression is a pattern the engine walks against a string. In the browser that engine is ECMAScript RegExp — not PCRE, not Python, not grep. Flags and Unicode behaviour differ, so a pattern that works in one flavour can fail in another.
The flags that change meaning
- g — find every match, not just the first
- i — ignore case
- m — ^ and $ match line edges, not only the whole string
- s — dot matches newline
- u / v — Unicode mode (they cannot be combined)
/\b([A-Z][a-z]+)\s+(\d{4})\b/gTest against real samples in Alphzen’s Regex Tester. The page uses new RegExp in your browser, so the result is what your frontend will see.
Replace is still a string
Replacement patterns such as $1 and $& are substitutions, not code. A tester that evals the replacement is a security hole. Alphzen does not do that.