I found this JS script here on SO that seems like it will work great for detecting both regular links and Twitter #hashtags and @usernames:
function processTweetLinks(text) {
text = text.replace();
var exp = /(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/i;
text = text.replace(exp, "<a href='$1' target='_blank'>$1</a>");
exp = /(^|\s)#(\w+)/g;
text = text.replace(exp, "$1<a href='http://search.twitter.com/search?q=%23$2' target='_blank'>#$2</a>");
exp = /(^|\s)@(\w+)/g;
text = text.replace(exp, "$1<a href='http://www.twitter.com/$2' target='_blank'>@$2</a>");
console.log(text);
}
BUT... The first expression doesn't quite suit my needs... When it gets something like http://google.com, it outputs <a href='http://google.com' target='_blank'>http://google.com</a>. I want it to output <a href='http://google.com' target='_blank'>google.com</a> instead - basically removing http:// or https:// from inside the anchor tags. I don't know regex - what would the function need to look like in order to output that?
UPDATE: I got the function fixed with @BrunoFinelli's answer, which works great, but I don't know how to make it fix multiple links in a given string/message. Right now it only fixes one each time I call the function... If anyone can adjust the function to fix this that'd be much appreciated! Thanks! It'd also be nice if the first regex (the one in question) removed www.'s as well from inside the anchor tags? But really I just need to know how to repeat this through a Tweet that may have more than one link/mention/hashtag. Thanks!