[re.finditer] Getting all occurences in one go?

Gilles Ganault nospam at nospam.com
Sun Apr 22 17:30:16 EDT 2007


On Sun, 22 Apr 2007 23:28:23 +0200, Gilles Ganault <nospam at nospam.com>
wrote:
>I'd like to make sure there isn't an easier way to extract all the
>occurences found with re.finditer:

Oops, s/match/item/:

req = urllib2.Request(url, None, headers)
response = urllib2.urlopen(req).read()
matches = re.compile("(\d+).html").finditer(response)
# ----------- BEGIN
for item in matches:
	if mytable[item]=="":
		mytable[item]= match.group(1)
	else:
		mytable[item]= mytable[item] + "," + match.group(1) #
----------- END



More information about the Python-list mailing list