python - 是否有 Perl 的 `study` 的 Python 等效项?

标签 python regex perl optimization

来自 Perl 的 documentation :

study takes extra time to study SCALAR ($_ if unspecified) in anticipation of doing many pattern matches on the string before it is next modified. This may or may not save time, depending on the nature and number of patterns you are searching and the distribution of character frequencies in the string to be searched;

我正在尝试加快我在 Python 中执行的一些正则表达式驱动的解析,我想起了 Perl 的这个技巧。我意识到我必须进行基准测试以确定是否有加速,但我在 Python 中找不到等效的方法。

最佳答案

Perl 的学习已经没什么用了。编译的正则表达式比创建 study 时更智能。

例如,它将备选方案编译成具有 Aho-Corasick 预测的 trie 结构。

使用 perl -Mre=debug 运行以查看正则表达式编译器和执行引擎应用的各种智能。

关于python - 是否有 Perl 的 `study` 的 Python 等效项?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9574196/

相关文章:

regex - 在 Awk 中使用正则表达式

javascript - 修改txt doc里面的 "string"值

perl - perl Carp模块中的无限循环

regex - Perl正则表达式匹配来自磁力链接的infohash

Python MySQLdb不会释放表锁

python - Flask看不到环境变量

小写字母或句点后跟大写字母的正则表达式

perl - re.pl : Variable not properly scoped inside block

python - 也许在字符串中添加额外的句子/单词

python - virtualenv 中 Pycharm 未解析的引用