F
Fortepianissimo
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!
--- 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!