Last active
September 26, 2015 13:28
-
-
Save marcinkuzminski/1104278 to your computer and use it in GitHub Desktop.
JS: Replaces found url patterns in text to a clickable link
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
/** | |
* Replaces found url patterns in text | |
* to a clickable link | |
*/ | |
function URL2Link(text) { | |
var pat = /(\b(https?):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig; | |
return text.replace(pat,"<a href='$1'>$1</a>"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment