Algorithm for finding and replacing URLs with hyperlinks

Morten W. Petersen morten at
Wed Feb 19 22:00:19 CET 2003

Peter Hansen wrote:
> "Morten W. Petersen" wrote:
>>Does anyone have a snippet of code that'll replace for example
>> with <a href=""
>> ></a>?
> How perfect do you want it?  Various packages include regular
> expression patterns which match URLs, although some are better
> than others.  The one in an older version of ZWiki which I 
> checked, for example, looks like this:
>  urlchars         = r'[A-Za-z0-9/:@_%~#=&\.\-\?]+'
>  url              = r'["=]?((http|ftp|mailto|file):%s)' % (urlchars)
> ...but unfortunately that means it will be confused if you try
> to put the URL at the end of a sentence like this

OK, I managed to make a function for replacing URLs with hyperlinks,
see attached code.  Thanks!  :)


-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
URL: <>

More information about the Python-list mailing list