lundi 12 mai 2014

Infinite Loop in Python Regex?


Vote count:

0




The seemingly simple regex command appears to put python into an infinite loop/hang:



import re
re.search(r"([A-Z]+\s*)+,", "UNITED STATES OF AMERICA ON BEHALF OF THE ENVIRONMENTAL")


I waited about 10 mins for the above command to complete, but it never did. However, the line below completes after about 5 to 10 seconds on my machine:



re.search(r"([A-Z]+\s*)+,", "UNITED STATES OF AMERICA ON BEHALF")


So is this a python bug or is the particular regex written very inefficiently? If the problem is the latter, why is that so and what can I do to fix it?



asked 15 secs ago






Aucun commentaire:

Enregistrer un commentaire