re.finditer背后的算法是什么?

What is the algorithm behind re.finditer?

我正在研究字符串搜索算法,经过几次尝试后,我发现 re.finditer 函数的结果比我的 Naive/KMP/Boyer-Moore 的实现要快得多。我读到 Python re libray 使用基本的回溯算法,但我想知道是否有人可以指出更具体的方向/代码,以便我可以更好地理解他们的算法?谢谢!

解决方案

假设您指的是 CPython。

函数定义在这里: https://github.com/python/cpython/blob/master/Lib/re.py#L243-L248

这里实现了回溯算法:https://github.com/python/cpython/blob/master/Lib/sre_compile.py