Hacker News new | ask | show | jobs
by epiphany47 5284 days ago
regexp != regular expression like xyzzyz said. This script uses backreferences which give regex's more "computing power" than regular expressions actually have, but remove the guaranteed runtime of an O(n) regular expression.

Quote: One common regular expression extension that does provide additional power is called backreferences. A backreference like \1 or \2 matches the string matched by a previous parenthesized expression, and only that string: (cat|dog)\1 matches catcat and dogdog but not catdog nor dogcat. As far as the theoretical term is concerned, regular expressions with backreferences are not regular expressions. The power that backreferences add comes at great cost: in the worst case, the best known implementations require exponential search algorithms, like the one Perl uses. Perl (and the other languages) could not now remove backreference support, of course, but they could employ much faster algorithms when presented with regular expressions that don't have backreferences, like the ones considered above.

via http://swtch.com/~rsc/regexp/regexp1.html

If that and the Wiki article still don't help you understand why regexp != regular expression, please ask. =]