[Tutor] re.findall vs. re.search and re.match

Ron Nixon nixonron at yahoo.com
Tue Mar 15 17:11:32 CET 2005

Thanks to all who replied to my post earlier on re's.
I'm still preplexed by why re.search and re.match
works in the code below, but not re.findall.
re.findall is suppose to return all non-voerlapping
occurances of the  pattern that matches in this
example, but it returns errors. Looking through the
docs and from what I can see it should work. Can
anyone provide advice.

import re
f = open('reformat.txt').read()
pat = re.compile(r"([^\r\n]+)\n([^\r\n]*)\n([^\r\n]*)
([^\r\n]*) ([^\r\n]*)")
name = x.group(1)
address = x.group(2)
citystate = x.group(3)+x.group(4)
zipcd = x.group(5)
o= open('reformat1.txt','w')
o.write("%s,%s,%s,%s\n" % (name, address,
print("%s,%s,%s,%s\n" % (name, address, citystate,zipcd))

Do you Yahoo!? 
Yahoo! Small Business - Try our new resources site!

More information about the Tutor mailing list