How it works
The pattern and its flags are compiled with the browser’s own RegExp constructor, so a syntax error is the engine’s complaint with its “Invalid regular expression” prefix removed, and the flag string is rebuilt in the order d g i m s u v y. Once typing pauses for 150 milliseconds the pattern is run over the test string with exec in a loop, as String.matchAll would: without g or y it stops at the first match, a zero-length match is stepped past by hand and the scan ends after 500 matches or 250 milliseconds. A second scan with g added finds out whether the flag would reach more, and the list says so.
The scan runs in a Web Worker rather than on the page. A single match attempt cannot be interrupted, so a pattern that backtracks catastrophically is handled by terminating the worker after one second and starting a fresh one for the next job; the page stays responsive and the result area says why there is nothing to show. Where no worker can be started — an old browser or a strict content security policy — matching runs inline, and a pattern flagged as catastrophic is not run over a test string longer than 2,000 characters. Matches are painted on a layer behind a transparent textarea, so the highlights sit under the real characters.
The explanation comes from a separate parser, which never throws: a half-typed pattern is explained as far as it goes. It walks alternations, sequences and atoms, folds a run of plain characters into one phrase, lists a character class item by item with A–Z and 0–9 named, nests a group over what it holds and turns a quantifier into words. The same walk numbers the capture groups that label the match list and flags an unbounded repeat of a group that already repeats without limit. The replacement preview is String.replace with the same regex, so $1, $<name>, $& and $$ behave as they will in your code.