Complexity of Regex substitution

前端 未结 8 1331
傲寒
傲寒 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条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-01 17:32

    To delve into theprise's answer, for the construction of the automaton, O(2^m) is the worst case, though it really depends on the form of the regular expression (for a very simple one that matches a word, it's in O(m), using for example the Knuth-Morris-Pratt algorithm).

提交回复
热议问题