Last active
August 29, 2015 14:07
-
-
Save MatthewVita/73594b7718c7a9b90e4d to your computer and use it in GitHub Desktop.
Hashtagify.js - Simple regex function that converts hashtags to urls
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
/* | |
*@desc: Simple regex function that converts hashtags to urls | |
*@usage: | |
* console.log("I love #JavaScript it's a fan#tastic language!".hashtagify()); | |
* ...returns `I love <a href="http://twitter.com/#!/search/#JavaScript">#JavaScript</a> it's a fan#tastic language!` | |
*/ | |
String.prototype.hashtagify = function() { | |
return (this.replace(/ (#[a-z0-9][a-z0-9\-_]*)/ig, ' <a href="http://twitter.com/#!/search/$1">$1</a> ')); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment