re problem

Joonas Paalasmaa joonas at olen.to
Fri Jun 15 21:00:26 CEST 2001


I have made a regular expression, that makes html links from plain
addresses.
It's almost ok but it doesn't work when there is no whitespace before an
address.
Shouldn't that '(?<!\S)' do the job?
And please tell me if you can find any other faults.


text = """http://www.python.org
and some text hTTp://www.pythonware.com and some more text
ftp://ftp.python.org"""

print re.sub(r'(?m)(?i)(?<!\S)(?P<address>(?:http|ftp):\S+)(?!\S)',
             r'<a href="\g<address>">\g<address></a>', text)

--
Joonas Paalasmaa



More information about the Python-list mailing list