You are probably encountering what is called a "super-linear" or
"exponential" match. This is the result of using nested quantifiers -
notably + and *. For instance, the following expression
^((ha)*)+$
matches the string "hahahaha", but not "hahahah". For a short string, a
non-match fails rather quickly. However, if we evaluate on the longer
string
"hahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahah",
the regex seems to hang and never return. This is all because there is a *
enclosed by a +. The + and * have to fight over who gets what, so the regex
backtracks, and the number of backtracks increases exponentially as the
string gets longer. If there is a match, the regex returns quickly, but if
it is a non-match, it could take years or even lifetimes to return. The
short answer is that you really have to check both successful and
unsuccessful inputs with both short and long strings to fully test a regular
expression for this behavior.
Brian Davis
www.knowdotnet.com