I know this has been talked here, but no solutions were offer to the exact problem. Please, take a look...
I'm using a function to transform plain-text URLs into clickable links. This is what I have:
<script type='text/javascript' language='javascript'>
window.onload = autolink;
function autolink(text) {
var exp = /(\b(https?|ftp):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/gim;
document.body.innerHTML = document.body.innerHTML.replace(exp,"<a href='$1'>$1</a>");
}
</script>
This makes
http://stackoverflow.com/
Looks like:
It works, but also replace the existent HTML links with nested links.
So, a valid HTML link like
<a href="http://stackoverflow.com/">StackOverflow</a>
Becomes something messy like:
<a href="http://stackoverflow.com/<a href="http://stackoverflow.com/">StackOverflow</a>">StackOverflow</a>...
How can I fix the expression to ignore the content of link tags? Thanks!
I'm a newbie... I barely understand the regex code. Please be gentle :) Thanks again.