Over a million developers have joined DZone.

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, '' + user + '')
	end
	txt
end
Topics:

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}