Converting Text Link To Hyper Link And Anchor Text
I have a question about converting text links to hyper links. I did it successfully by using this code from this link; How to replace plain URLs with links? function replaceURLWith
Solution 1:
This works!!!
functionreplaceURLWithHTMLLinks(text) {
var exp = /(\b(http|ftp|https):\/\/([\w-]+\.[\w-]+)+([\w.,@?^=%&:\/~+#-]*[\w@?^=%&\/~+#-])?)/ig;return text.replace(exp,"<a href='$1'>$3</a>");
}
Input text
"http://stackoverflow.com/questions/579335/javascript-regexp-to-wrap-urls-and-emails-in-anchors";
Output:
<ahref='http://stackoverflow.com/questions/579335/javascript-regexp-to-wrap-urls-and-emails-in-anchors'>stackoverflow.com</a>
Here is a working JsFiddle
Post a Comment for "Converting Text Link To Hyper Link And Anchor Text"