#!/usr/bin/python
# -*- coding: ISO-8859-15 -*-
import re
recherche_site = r'(https|ftp|http+://+[^ \t\n\r\f\v\<]?*)'
remplace_site = r'<a href="\1" target="_blank">\1</a>'
recherche_mail = r'([\w\‑]?[\w\‑\.]?+@[\w\‑]?[\w\‑\.]?+[a‑zA‑Z]?{1,4})'
remplace_mail = r'<a href="mailto:\1">\1</a>'
def remplace_liens(texte):
return re.sub(recherche_mail, remplace_mail, texte, re.I)
if __name__ == '__main__':
print 'saisissez un texte (une ligne vide pour terminer)'
texte = []?
saisie = True
while saisie:
ligne = raw_input()
if ligne == '':
saisie = False
else:
texte.append(ligne)
texte = '\n'.join(texte)
print 'résultat:'
print remplace_liens(texte)