Created
April 29, 2013 16:37
-
-
Save Usse/5482841 to your computer and use it in GitHub Desktop.
Wrap with an <a> element all the link occurrences in a string.
This file contains hidden or 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 test_if_link(string) { | |
var thestring=string; | |
var pattern = /(\b(www\.|http\:)\S+\b)/gi; | |
return thestring.replace(pattern, "<a href='$1' target='_blank'>$1</a>"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment