Yes, this is entirely possible. you can even explore the automaton eagerly and detect if it's possible to loop from an accepting state to a nonaccepting one.
Ripgrep does something like thhis. It has a meta regex engine that switches engine when it finds what looks like pathological cases (or rather, the regex-automata crate does, which is used by the regex crate, which powers ripgrep).
> 1,000 0.7ms 28us 25x
> 5,000 18ms 146us 123x
> 10,000 73ms 303us 241x
> 50,000 1.8s 1.6ms 1,125x
Why is there a normal mode if hardened mode is faster for all input sizes?
reply