for url in re.findall(pat_url, text):
    text = text.replace(url[0], '<a href="%(url)s">%(url)s</a>' % {'url':
        url[0]})
for email in re.findall(pat_email, text):
    text = your_string.replace(email[1], 
        '<a href="mailto:%(email)s">%(email)s</a>' % {'email': email[1]})
return text
if __name__ == '__main__':
    pass
Detect URLs in a string and wrap with "<a href..." tag