One important consideration can also be whether the text actually matches the regular expression. Take (as a contrived example) the regex (x+x+)+y
from this regex tutorial.
When applied to xxxxxxxxxxy
it matches, taking the regex engine 7 steps. When applied to xxxxxxxxxx
, it fails (of course), but it takes the engine 2558 steps to arrive at this conclusion.
For xxxxxxxxxxxxxxy
vs. xxxxxxxxxxxxxx
it's already 7 vs 40958 steps, and so on exponentially...
This happens especially easily with nested repetitions or regexes where the same text can be matched by two or more different parts of the regex, forcing the engine to try all permutations before being able to declare failure. This is then called catastrophic backtracking.