Live data from Hacker News

Finding all regex matches has always been O(n²)

iev.ee

81–82 of 82 posts

Re: Finding all regex matches has always been O(n²)

#81
post #67
post #55

> no capture groups > [...] > no lazy quantifiers - .*? Here's the caveats. And so running a regex engine on the matches seems like it would get you back to O(regexlen * haystacklen * matchcount) or roughly O(mn²) again.

It's still O(n * m). The matches are non-overlapping, even if you run a separate engine on the matches post-match it will at most traverse the full input once across all matches.

Ture, I forgot about the non-overlapping matchss and that that will cancel out any extra n parameter.

Actually rereading again, it almost seems like it should be possible to do the matching as a special case of the Thompson/Pike VMs and have it loop back around to the start, and deduplicate multiples, but I am only speculating.

Re: Finding all regex matches has always been O(n²)

#82
post #80
post #7

Earlier quoted context omitted.

What's with this silly "all lower case" style lately? Jack Dorsey's layoff message last month did the same thing. Is it some kind of "Prove you're not an AI by purposely writing like an idiot" or something?

it's been common in the unix/c/lisp worlds since before you were born when 6 bit ascii was all caps only, people got used to monocase, then 7-bit lowercase ascii blew in a fresh wind.

What a condescending comment. It's too bad I can't vote you down.
Post reply on HN