Geeks With Blogs
.Nettuce Code Salad

It's annoying when you know you've seen and used something before only for it to be lost in the myraid of archived Visual Studio projects that litter my hard drive, and I 've no idea of the search terms IĀ used to find it on the net in the first place. Luckily I found some regular expressions that almost worked so rolled my own:

function Linkify(text) {
text
= text.replace(/(https?:\/\/\S+)/gi, function (s) {
return '<a href="' + s + '">' + s + '</a>';
});

text
= text.replace(/(^|)@(\w+)/gi, function (s) {
return '<a href="http://twitter.com/' + s + '">' + s + '</a>';
});

text
= text.replace(/(^|)#(\w+)/gi, function (s) {
return '<a href="http://search.twitter.com/search?q=' + s.replace(/#/,'%23') + '">' + s + '</a>';
});
return text;
}
Posted on Wednesday, March 3, 2010 11:02 AM | Back to top


Comments on this post: Javascript Twitter Linkify

# re: Javascript Twitter Linkify
Requesting Gravatar...
Ahhh. Thank you, thank you. :) I'm working on a chrome extension and I needed this badly.

Cheers,
Jane
Left by Jane on Nov 26, 2012 4:39 AM

Your comment:
 (will show your gravatar)


Copyright © Jon Canning | Powered by: GeeksWithBlogs.net