def fix_urls(text):
    pat_url = re.compile(
        """
                     (?x)( 
         (http|ftp|gopher) 
                       :// 
            (\\w+[:.]?){2,} 
                      (/?| 
                [^ \\n\\r"]+ 
                    [\\w/]) 
         (?=[\\s\\.,>)'"\\]]) 
                         ) 
                           """
        )
pat_email = re.compile(
    """
                    (?xm)  
                 (?=^.{11} 
         (?<!Message-ID:|  
             In-Reply-To)) 
                    (.*?)( 
        ([A-Za-z0-9-]+\\.)? 
             [A-Za-z0-9-]+ 
                         @ 
              (\\w+\\.?){2,} 
         (?=[\\s\\.,>)'"\\]]) 
                         ) 
                           """
    )
for url in re.findall(pat_url, text):
    pass
Detect URLs in a string and wrap with "<a href..." tag