Regular Expressions Will Stab You in the Back
tech.blog.cueup.com
tech.blog.cueup.com
The rather interesting analysis is here:
http://swtch.com/~rsc/regexp/regexp1.html
Not that it's a free lunch, since you're gaining a constant amount of overhead in exchange for a sane growth pattern.
EDIT: Of course the article would mention RE2. That's what I get for reading the comments before TFA...
Regarding speed, I've actually found that re2 is faster on some non-pathological regexps, and a little slower on most. As usual, if you care about this, benchmark it. I've managed to get some easy 2x speedups by switching from Python's re to re2, even though re is usually faster.
http://swtch.com/~rsc/regexp/regexp2.html
It isn't nearly as highly optimized as RE2, but it works in a similar way.
However the solutions given, if you do end up with this problem, are good and detailed.
They did miss perl's solution, Special Backtracking Control Verbs : http://perldoc.perl.org/perlre.html#Special-Backtracking-Con...
http://swtch.com/~rsc/regexp/regexp1.html
The sky isn't falling, but it's still possible to get struck by lightning. (And of course, you're vulnerable to DoS attacks if you run user-supplied regexps with backreferences -- this is provably NP-hard.)
We are of course up to 5.16.1 these days, and I'd be more inclined to pay attention to benchmarks if they were performed with remotely current versions of the software.
Otherwise, thanks for the enlightening post.
"aaaaaaaaaaaaaaaaaaaaaaaaaaa" =~ /a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?aaaaaaaaaaaaaaaaaaaaaaaaaaa/I recognize that you're trying to demonstrate pathologically bad behavior, but as written, you've got a pathologically bad regex.
Note the speed up from 24 & 30 seconds to seven one-thousandths of a second in both cases. Again, I like the idea of a regex engine with different design considerations than Perl's.
Your article would have been much better if it has used a class of pathological data with real world examples, and not used contrived examples that I rewrote in less time than it took to run.
So here's my results:
5.14.2:
$ time perl -e 'print "aaaaaaaaaaaaaaaaaaaaaaaaaaa" =~ /a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?aaaaaaaaaaaaaaaaaaaaaaaaaaa/ '
1
real 0m24.227s
user 0m24.210s
sys 0m0.008s
$ time perl -e 'print "aaaaaaaaaaaaaaaaaaaaaaaaaaa" =~ /a{0,27}aaaaaaaaaaaaaaaaaaaaaaaaaaa/ '
1
real 0m0.007s
user 0m0.004s
sys 0m0.004s
----------------------------------5..8.8:
$ time perl -e 'print "aaaaaaaaaaaaaaaaaaaaaaaaaaa" =~ /a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?aaaaaaaaaaa aaaaaaaaaaaaaaaa/ '
1
real 0m30.065s
user 0m30.046s
sys 0m0.016s
$ time perl -e 'print "aaaaaaaaaaaaaaaaaaaaaaaaaaa" =~ /a{0,27}aaaaaaaaaaaaaaaaaaaaaaaaaaa/ '
1
real 0m0.007s
user 0m0.004s
sys 0m0.004s
--------------------------------I'm still impressed with the new regex engine, but I have a pathological hatred of contrived examples.
It's not you, it's me.