Regular expressions trouble
Darrell Gallion
dgallion1 at yahoo.com
Mon Jun 5 13:13:15 EDT 2000
<vivienne_van_velzen at my-deja.com> wrote in message
news:8hgcn2$1lh$1 at nnrp1.deja.com...
> I'm fairly new to the use of regular expressions,
and I've come upon a
> problem I can't seem to fix. I'm trying to extract a
keyword from a
> HTML-page and color it red. This works fine, except
that it also
> extracts the keywords within tags.
import re
def main():
buf = open("mozilla_org.htm").read()
keyWords=['help']
pat='(>[^<]*)(%s)'
for p in keyWords:
buf = re.sub(pat%p,'\g<1><b><font
color=\"red\">\g<2></font></b>',buf)
open("test.htm","w").write(buf)
main()
--Darrell Gallion
__________________________________________________
Do You Yahoo!?
Yahoo! Photos -- now, 100 FREE prints!
http://photos.yahoo.com
More information about the Python-list
mailing list