Algorithm for finding and replacing URLs with hyperlinks
Morten W. Petersen
morten at nidelven-it.no
Wed Feb 19 22:04:34 CET 2003
Morten W. Petersen wrote:
> Peter Hansen wrote:
>> "Morten W. Petersen" wrote:
>>> Does anyone have a snippet of code that'll replace for example
>>> http://www.python.org with <a href="http://www.python.org"
>> 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 http://www.python.org.
> OK, I managed to make a function for replacing URLs with hyperlinks,
> see attached code. Thanks! :)
Ajajaj, attached an old module. Here's the correct one that works.
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
More information about the Python-list