Demonstration of exponential growth of search time for some regular expressions

It is well-known [1, 2] that in some cases, search time for matching a regular expression in a string of length n can grow exponentially in n.
Ben Tilly discussed this in Perlmonks , and explained how Perl 5.6 manages to avoid some of these scenarios, with the cost of slightly worse performance for all regexp searches.

In many other languages / implementations, regexp search time might explode.
Here is a demonstration in Javascript.

The string in which we search is a concatenation of copies of 'abc ' ,
and the characters appended at the end:

_
The question we ask is whether this string consists only of repetitions of 'abc', with optional whitespace between them, and optional whitespace at the beginning and at the end of the string.
result: _

calculation time: _

Use this regexp:


You'd better start with a small number of copies of 'abc '.
If you run the 1st regexp on a non-matching string with more than ~ 23 copies of 'abc ', be prepared to wait... or to kill the browser.
Itai