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

Gilles Ganault nospam at nospam.com
Mon Mar 16 01:25:01 CET 2009


On Mon, 16 Mar 2009 01:14:00 +0100, Gilles Ganault <nospam at nospam.com>
wrote:
>I'm stuck at why Python doesn't return the first line in this simple
>regex

Found it: Python does extract the token, but displaying it requires
removing hidden chars:

=====
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()

	#Important!
	for item in ["\t","\r"," <br />"]:
		address = address.replace(item,"")

	print "address is %s" % address
else:
	print "address not found"
=====

HTH,



More information about the Python-list mailing list