[ActivePython 2.5.1.1] Why does Python not return first line?

Gilles Ganault nospam at nospam.com
Sun Mar 15 20:14:00 EDT 2009


Hello

I'm stuck at why Python doesn't return the first line in this simple
regex:

===========
response = "<span>Address :</span></td>\r\t\t<td>\r\t\t\t3 Abbey Road,
St Johns Wood <br />\r\t\t\tLondon, NW8 9AY\t\t</td>"

re_address = re.compile('<span>Address
:</span></td>.+?<td>(.+?)</td>',re.I | re.S | re.M)

address = re_address.search(response)
if address:
	address = address.group(1).strip()
	print "address is %s" % address
else:
	print "address not found"
===========
C:\test.py
                        London, NW8 9AY<br />
===========

Could this be due to the non-printable characters like TAB or ENTER?
FWIW, I think that the original web page I'm trying to parse is from a
*nix host.

Thanks for any hint.



More information about the Python-list mailing list