Regular expressions, in the strict formal sense, have
an important property: they completely express the set
of patterns that can be searched for in a single linear-time
pass through the text.  That is, they have an associated
linear-time performance guarantee.

In your particular case, adding recursion would produce
context-free expressions, and general context-free parsing as
typically implemented is cubic as opposed to linear.
(It turns out to be the same problem as matrix multiplication,
so with a lot more effort you could get it down to n^2.38 or
perhaps even lower, but you can't possibly get sub-quadratic.)

As Charles pointed out, there is a long, distinguished
history of editors and other tools making regular expressions
more expressive.  It is important to remember that this
is always done at the cost of giving up the performance
guarantee, at least in some cases.  And unless a general
matcher can distinguish the different cases and implement
separate algorithms for each, it usually gives up the
performance guarantee in all cases.

Russ

Reply via email to