FWIW, nim-regex does achieve linear time in the rebar test[0], even if the regex includes capture groups. It's NFA based. [0]: https://github.com/BurntSushi/rebar/pull/20#issuecomment-256...
Finding all regex matches has always been O(n²)
41–50 of 82 posts
Re: Finding all regex matches has always been O(n²)
#42Re: Finding all regex matches has always been O(n²)
#43Earlier quoted context omitted.
The fact that terms like Aho-Corasick, PLDI, Go, etc. are properly capitalized, including if they begin sentences, but otherwise sentences are uncapitalized, makes me think it's an explicit LLM instruction "don't capitalize the start of sentences" rather than writing style.
ChatGPT also loves Aho-Corasick and seems to overuse it as an optimization fall back idea. ChatGPT has suggested the algorithm to me but the code ended up slowing down a lot.
Re: Finding all regex matches has always been O(n²)
#44Re: Finding all regex matches has always been O(n²)
#45I would argue that hardened mode should be default though, similar to how siphash is the default hashing function in Rust hash maps. Faster mode should be opt in if the user is confident that the supplied data is nonmalicious and they need the speed up.
Re: Finding all regex matches has always been O(n²)
#46FWIW, nim-regex does achieve linear time in the rebar test[0], even if the regex includes capture groups. It's NFA based. [0]: https://github.com/BurntSushi/rebar/pull/20#issuecomment-256...
Oh that is interesting! I haven't even looked Nim regex until now, is it similar to the approach in Go?
Re: Finding all regex matches has always been O(n²)
#47Great stuff. I would argue that hardened mode should be default though, similar to how siphash is the default hashing function in Rust hash maps. Faster mode should be opt in if the user is confident that the supplied data is nonmalicious and they need the speed up.
Going forward this and the extended operators + large pattern perf will hopefully be a strong selling point to gain more traction
Re: Finding all regex matches has always been O(n²)
#48@ievev Have you ever seen an implementation like @bablr/regex? https://github.com/bablr-lang/regex-vm It's an NFA system so it isn't going to be winning any awards for throughput, but in this particular case it does seem to completely avoid the complexity blowup. It will run your heap out of memory though on really big inputs. The strategy this engine uses is just to evolve the state as a function of time. A match ca…
For example in the expression in your example (I'm assuming based on your description of the test data that /d+s+/ means the same as /\d+\s+/ in the RE engines I've used) any match must contain a digit followed by a space.
A scan for all places where a digit is followed by whitespace with each such place then being checked to find the length of the string of whitespace starting there and the length of the string of digits ending there should be linear time and constant heap space.
Re: Finding all regex matches has always been O(n²)
#49I find it weird to have the Perl innovation (?:...) be called "traditional regex". Perl was rather innovative back then, even if it's more than 30 years ago now. Traditional regex is what came before it (grep -E being the most advanced form). I wonder what counts as nontraditional in the author's eyes.
In my head a regex-like thing of Perl origin is known as a 'perlex'.
Re: Finding all regex matches has always been O(n²)
#50@ievev Have you ever seen an implementation like @bablr/regex? https://github.com/bablr-lang/regex-vm It's an NFA system so it isn't going to be winning any awards for throughput, but in this particular case it does seem to completely avoid the complexity blowup. It will run your heap out of memory though on really big inputs. The strategy this engine uses is just to evolve the state as a function of time. A match ca…
Do any RE implementations do anything like the query planning that databases do or the rewrites that compilers do that can replace the RE with a different sequence of REs or string searches that might execute faster? For example in the expression in your example (I'm assuming based on your description of the test data that /d+s+/ means the same as /\d+\s+/ in the RE engines I've used) any match must contain a digit f…