Pour l'instant, je le regex suivant pour le remplacement d'une URL à un lien hypertexte HTML:Regex pour l'URL de lien hypertexte
msg = msg.replace(/(\b((https?|ftp|file):\/\/|www.)[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/gi, "<a href='out.php?u=$1'>$1</a>");
Cette remplace
http://www.stackoverflow.com
dans
<a href='out.php?u=http://www.stackoverflow.com'>http://www.stackoverflow.com</a>
Mais maintenant j'ai un problème. Lorsque j'ai déjà un lien hypertexte, je ne veux pas remplacer l'URL de ce lien hypertexte par un nouveau lien hypertexte.
Alors:
<a href='http://www.stackoverflow.com'>Stackoverflow</a>
ne doit pas devenir:
<a href='<a href='out.php?u=http://www.stackoverflow.com'>http://www.stackoverflow.com</a>'>Stackoverflow</a>
Est-ce que quelqu'un sait comment je peux empêcher cela?
Je pense que cela a déjà été répondu: http://stackoverflow.com/questions/37684/how-to-replace-plain-urls-with-links –