Python re infinite execution

前端 未结 4 2239
日久生厌
日久生厌 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:29

    Looks like it might be something in your pattern. I'm not sure what you are trying to do with the last '*' in your expression. The following code seems to work for me:

    import re
    
    pattern = r"(\w+)\*([\w\s]+)$"
    
    re_compiled = re.compile(pattern)
    
    results = re_compiled.search('COPRO*HORIZON 2000                 HOR')
    
    print(results.groups())
    

提交回复
热议问题