automate linking to Twitter users
1 2 def link_twitter_user(txt) 3 if match = txt.match(/.*?(@)((?:[a-z][a-z]+))(:|\s)/i) 4 user = match[2] 5 txt.gsub!(user, '<a href="http://twitter.com/' + user + '">' + user + '</a>') 6 end 7 txt 8 end
DZone Snippets > labuschin > auto_link
12723 users tagging and storing useful source code snippets
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
Martin Labuschin http://labuschin.com
1 2 def link_twitter_user(txt) 3 if match = txt.match(/.*?(@)((?:[a-z][a-z]+))(:|\s)/i) 4 user = match[2] 5 txt.gsub!(user, '<a href="http://twitter.com/' + user + '">' + user + '</a>') 6 end 7 txt 8 end