Python re infinite execution

前端 未结 4 2242
日久生厌
日久生厌 2020-12-05 18:40

I\'m trying to execute this code :

import re
pattern = r\"(\\w+)\\*([\\w\\s]+)*/$\"
re_compiled = re.compile(pattern)
results = re_compiled.search(\'COPRO*H         


        
4条回答
  •  南笙
    南笙 (楼主)
    2020-12-05 19:23

    Try re2 or any other regular expression engine base on automata theory. The one in a current python re module is a simple and slow backtracking engine (for now, things may change in future). But automata based engines have some restriction, it wouldn't allow you to use backreferences for example. Collate with this re2 syntax page to find out will it satisfy your needs or not.

提交回复
热议问题