Skip to content

Instantly share code, notes, and snippets.

@MatthewVita
Last active August 29, 2015 14:07
Show Gist options
  • Save MatthewVita/73594b7718c7a9b90e4d to your computer and use it in GitHub Desktop.
Save MatthewVita/73594b7718c7a9b90e4d to your computer and use it in GitHub Desktop.
Hashtagify.js - Simple regex function that converts hashtags to urls
/*
*@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