Как то так?
import re
import xml.sax.saxutils
def anchor_from_email_address_match(match):
address = match.group(0)
return "<a href=%s>%s</a>" % (
xml.sax.saxutils.quoteattr("mailto:" + address),
xml.sax.saxutils.escape(address))
def replace_email_addresses_with_anchors(text):
return re.sub("\w+@(?:\w|\.)+", anchor_from_email_address_match, text)
print replace_email_addresses_with_anchors(
"An address: bob@example.com, and another: joe@example.com")