Created
November 5, 2018 12:58
-
-
Save smitroshin/2e2b933d36f422b1247fb92d71aa65d9 to your computer and use it in GitHub Desktop.
urlify
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function urlify(text) { | |
var urlRegex = /(https?:\/\/[^\s]+)/g; | |
return text.replace(urlRegex, function(url) { | |
return '<a href="' + url + '">' + url + '</a>'; | |
}) | |
} | |
var text = "Find me at http://www.example.com and also at http://stackoverflow.com"; | |
var html = urlify(text); | |
// html now looks like: | |
// "Find me at <a href="http://www.example.com">http://www.example.com</a> and also at <a href="http://stackoverflow.com">http://stackoverflow.com</a>" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment