Tame a regex that blows up (ReDoS) with an equivalent pattern that stays fast: 18 levels of catastrophic backtracking and nested quantifiers.
ReDoS (Regular expression Denial of Service): one short string keeps the engine busy counting, and everyone in the queue waits with it. This browser's regex engine (V8's Irregexp), like PCRE in PHP, Java and Python's re, works by backtracking: it tries one way of reading the string, and at a dead end goes back to the last choice and tries another. A repetition inside a repetition gives a string that almost matches a huge number of ways to be read, and every one is tried. The kecamatan's screen counts that engine's steps, and the small board in its corner times this browser's real RegExp, stopped when it runs too long.
A knot does not always look like + inside +. When a repetition holds a separator that may be missing, turns in a row can stick together, and the same run of characters can be split into turns in many ways. The result is the same as a repetition inside a repetition.
Not every knot explodes as 2^n. Two neighbouring quantifiers that can eat the same characters have only n ways to share n characters, but every way is checked to the end of the string: about n² steps. Twice as long, four times as slow. On a string of thousands of characters, that is enough to make a server stall.
test() looks for the rule anywhere in the string: when it fails from the first character it tries again from the second, the third, and so on. A rule with no ^ that runs far from every position and then fails at the end makes its steps grow as n², even with no repetition inside a repetition.
Sometimes the old rule is wrong as well as slow: it takes what it should refuse. On a level like this the language may change, and what counts are the slips in the book: green ones must be taken, red ones refused. A rule that names the right shape exactly usually has no knot at all.
Validators passed around the internet often carry knots. OWASP's ReDoS page lists this email validator as an example. Your new rule must mean exactly the same as the old one: Bu Lastri reads every slip in one pass, like the RE2 engine, and will show the first slip where the two rules differ.