Regular expression implementation details

前端 未结 3 2068
时光说笑
时光说笑 2020-12-05 03:17

A question that I answered got me wondering:

How are regular expressions implemented in Python? What sort of efficiency guarantees are there? Is the implementation \

3条回答
  •  不思量自难忘°
    2020-12-05 04:12

    Python's re module was based on PCRE, but has moved on to their own implementation.

    Here is the link to the C code.

    It appears as though the library is based on recursive backtracking when an incorrect path has been taken.

    alt text

    Regular expression and text size n
    a?nan matching an

    Keep in mind that this graph is not representative of normal regex searches.

    http://swtch.com/~rsc/regexp/regexp1.html

提交回复
热议问题