finding all regex matches has always been O(n²). even in the engines built to prevent it

every regex engine that promises linear time breaks that promise the moment you ask for all matches. the problem has been there since the 70s, hiding in plain sight.
— by ian erik varatalu

šŸ¤” https://iev.ee/blog/the-quadratic-problem-nobody-fixed/

#regex #problem #coding #70s #blogpost #find #blog #liner #lineartime #time

finding all regex matches has always been O(n²). even in the engines built to prevent it | ian erik varatalu

every regex engine that promises linear time breaks that promise the moment you ask for all matches. the problem has been there since the 70s, hiding in the iteration loop.

ian erik varatalu

@kubikpixel

that's why i always avoided regex as much as possible and only use it in edge/specific cases
not only because it's hard to handle, but also because i noticed that it can create significant overhead in very simple tasks
furthermore, i aggregate before i pass it to regex
i never understood why regex is used so prominently, especially in generic situations, and is the accepted answer in soo many stack* questions

@kubikpixel

a teacher once told me: only use/pass what you absolutely need
and if you need to write 30 lines to get there instead of 10 with an infinit/unknown regex iteration, go for the 30 lines

@pmj i'm a regex fanboy but yes not use it everywhere and yes it's slow. i only use it if something really needs to be checked (by users) e.g. it's really an email (p.s. clumsy example, because there are some libs that are a lot better for that).