Skip to content

Instantly share code, notes, and snippets.

@jaydonnell
Created August 19, 2011 18:15
Show Gist options
  • Save jaydonnell/1157561 to your computer and use it in GitHub Desktop.
Save jaydonnell/1157561 to your computer and use it in GitHub Desktop.
def self.link_hashtags(s)
s.gsub(/( |^)#[a-zA-Z0-9][^#\s-]*/) { |match| '<a href="/search?q=' + CGI.escape(match) + '">' + match + '</a>'}
end
#bob #jay
should become
<a href="/search?q=#bob">#bob</a> <a href="/search?q=#jay">#jay</a>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment