Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Actually, this is false. A lot of regex implementations use a backtracking approach in all cases, causing pathological behavior even on regexes which match a regular language (and so should never take any significant amount of time to process).

See https://swtch.com/~rsc/regexp/regexp1.html, which gives

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?a?a?a?aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa

(see the backtracking? me neither) as an example.



You are right. The support of fancy features like backtracking should not cause any degradation of performance for simple regular expressions. You are not obliged to use them, but they should not hurt you when you do not use them. I am surprised this issue is not fixed in perl.


EDIT: Actually, nevermind. Does not matter in the grand scheme of things.


> (see the backtracking? me neither)

If I understand the article correctly, the Perl regex evaluator, if given a string consisting of only the minimum required number of 'a's, first matches them to the optional 'a's, and then has to backtrack to match the required 'a's.


I misspoke a little. The point is that that expression doesn't use backreferences, and therefore doesn't need to use backtracking at all. The fact that it does use backtracking anyway is the focus of the complaint.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: