Never been to DZone Snippets before?

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 (See related posts)

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 on this post

dbloete posts on Sep 27, 2007 at 12:59
;)

You need to create an account or log in to post comments to this site.


Click here to browse all 4861 code snippets

Related Posts