re problem

Joonas Paalasmaa joonas at
Fri Jun 15 15:00:26 EDT 2001

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

text = """
and some text hTTp:// and some more text"""

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