Created
December 4, 2012 19:39
-
-
Save ahmednuaman/4207874 to your computer and use it in GitHub Desktop.
Linkify a tweet
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
String.prototype.linkify = function() | |
{ | |
var str = this.toString(); | |
str = str.replace(/(https?:\/\/[^\s]+)/gim, '<a href="$1">$1</a>', str); | |
str = str.replace(/([#|@][^\s]+)/gim, '<a href="http://twitter.com/$1">$1</a>', str); | |
return str; | |
} | |
'Here\'s an @test and an #test'.linkify() // -> Here's an <a href="http://twitter.com/@test">@test</a> and an <a href="http://twitter.com/#test">#test</a> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment