Complexity of Regex substitution

前端 未结 8 1327
傲寒
傲寒 2020-12-01 16:58

I didn\'t get the answer to this anywhere. What is the runtime complexity of a Regex match and substitution?

Edit: I work in python. But would like to know in genera

8条回答
  •  佛祖请我去吃肉
    2020-12-01 17:07

    You can trade space for speed by building a nondeterministic finite automaton instead of a DFA. This can be traversed in linear time. Of course, in the worst case this could need O(2^m) space. I'd expect the tradeoff to be worth it.

提交回复
热议问题