Your understanding is flawed.

Try these actions and ponder their significance...

>>> s = '<<html><head><title>Title</title>'
>>> re.search('<.*?>',s).group()
'<<html>'
>>> re.search('<.*>',s).group()
'<<html><head><title>Title</title>'
>>> s = '<<html><head><title>Title-title'
>>> re.search('<.*>',s).group()
'<<html><head><title>'
>>> re.search('<.*t',s).group()
'<<html><head><title>Title-tit'
>>> re.search('<.*?t',s).group()
'<<ht'
>>>


The non greediness applies to what follows the '?' not what precedes it.
That is, it swallows everything up until the last possible matching pattern by default. Non greedy only swallows up to the first matching pattern after the ?

HTH

--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/

_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to