[Regex] Search and replace?

Gilles Ganault nospam at nospam.com
Thu Nov 13 04:55:24 EST 2008


Hello

I need to iterate through a variable, and for each pattern that
matches, replace this with something else.

I read the chapter in www.amk.ca/python/howto/regex/, but the output
is wrong:

=======
#Extract two bits, and rewrite the HTML
person = re.compile('<tr onMouseOver=(?P<item1>.+?)>.+?<a
onmouseover="Tip(?P<item2>.+?) </td>')

output = person.sub('<tr onMouseOver=\1><td><a
onmouseover="Tip\2</td>', input)
=======

Does someone have a simple example handy so I can check what's wrong
with the above?

Thank you.



More information about the Python-list mailing list