[Tutor] Regex troubles

JRicker joejava@dragoncat.net
Sat, 21 Apr 2001 00:31:15 -0400


Ok I'm at wits end here and would love to hear some ideas on what I'm
doing wrong here.

I'm trying to match all occurances of this text in a web page:

<font color="">Some Text
</font>

I want to be able to search for that text plus match certain keywords,
and return the text between the two tags if the keyword appears anywhere
in the text.

Some code:

keywords = "[Foobar|Some]"
keyword_re = re.compile("<font color=\"\">(.*?" + keywords +
".*?)</font>", re.I | re.DOTALL)
for x in re.findall(keyword_re, apage):
        print x

where apage is a web page .read() in.  Now this is returning everything
between each appearance of <font color=""></font> whether the keywords
match or not.

Something else that struck me as odd.  I tried making keywords a single
word to search for (ie keywords = "Some") and my script crashed giving
me an error of maximum recursion level reached.  Any ideas what caused
this?

Thanks
Joel