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

Is there a difference between greedy and non-greedy atoms?



In the order of searching and hence the match you can get, yes. In performance in the case of a non-match, no.


The regex a?a?a?a?a?aaaaa against the string aaaaa will complete in linear time if you use non-greedy ?s but with greedy matching it has exponential complexity. So, there is a difference.




Consider applying for YC's Fall 2025 batch! Applications are open till Aug 4

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

Search: