Skip to content

Instantly share code, notes, and snippets.

View yussan's full-sized avatar
🏠
Working from home everyday

yussan yussan

🏠
Working from home everyday
View GitHub Profile
@danro
danro / twitter-text.js
Created October 14, 2011 17:35
Parse links & usernames in twitter text.
// parses the text in a tweet and adds links to users, hash tags and urls
parseTweet: function (text) {
// parse urls
text = text.replace(/[A-Za-z]+:\/\/[A-Za-z0-9_-]+\.[A-Za-z0-9_:%&~\?\/.=-]+/g, function(url) {
return url.link(url)
})
// parse usernames
text = text.replace(/[@]+[A-Za-z0-9_-]+/g, function(u) {
var username = u.replace("@","")
return u.link("http://twitter.com/"+username)