DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world
Automate Linking To Twitter Users
this method searches for @some_user in a string (txt) and links found matches to the twitter-page of some_user
def link_twitter_user(txt) if match = txt.match(/.*?(@)((?:[a-z][a-z]+))(:|\s)/i) user = match[2] txt.gsub!(user, '<a href="http://twitter.com/' + user + '">' + user + '</a>') end txt end





Comments
Snippets Manager replied on Thu, 2007/09/27 - 7:54am