regex searching hangs

Fortepianissimo fortepianissimo at yahoo.com.tw
Sun Feb 8 10:29:10 EST 2004


Could someone explains why the following code hangs (Python 2.3.3)?

--- CODE STARTS ---
import re

p=re.compile(r'\S+(?:\.\S+)+\.com')

t='......................................'
p.search(t)
--- CODE ENDS ---

>From the syntax and semantics of regex, the entire t should be
consumed by the pattern '\S+(?:\.\S+)+' and the search() call should
return None. Is search() doing a depth-first search and can't pulling
itself out? It doesn't seem right to me, or I'm missing something?

BTW, I don't think any regex matching should ever hang in any
circumstances - correct me if I'm wrong: is halting problem a problem
here?

Thanks!



More information about the Python-list mailing list