Short version: drop this in the
<head> of your HTML:
and your browser has (basic/poyfillable) support for a lot of modern features. You can also specify which feature you want…
Fortunately, you can emulate atomic grouping with LookAhead.
(?=(a))\1. It works by matching (and capturing) the sub-expression in a LookAhead non character-consuming assertion, then matching it (effectively consuming the characters) with a backreference, not allowing backtracking at this point.
As possessive quantifiers like
a++ have a strict equivalent using atomic grouping (here
(?>a+)), we can also leverage this technique:
There are two downsides though: it complexifies the regex and it inserts a possibly unwanted capturing group for the sole purpose of matching. But still, it may still be a useful trick to know since the JS regex flavor is a bit sub-par.