Regular expressions trouble

vivienne_van_velzen at my-deja.com vivienne_van_velzen at my-deja.com
Mon Jun 5 10:16:17 EDT 2000


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.
Code example:

newline = re.sub('([^<>]*?)((?:<[^<>]*?>[^<>]*?)*?)('+query+')','\g<
1>\g<2><b><font color=\"red\">\g<3></font></b>',newline)

Query is the keyword and newline is a line from the HTML page.
The expression works in Perl with the use of \G. I couldn't find a
replacement in Python's re-module.
I hope someone can help me out.
TIA,

Vivienne


Sent via Deja.com http://www.deja.com/
Before you buy.



More information about the Python-list mailing list