Skip to content

Instantly share code, notes, and snippets.

@th1agoalmeida
Created November 5, 2010 19:37
Show Gist options
  • Save th1agoalmeida/664654 to your computer and use it in GitHub Desktop.
Save th1agoalmeida/664654 to your computer and use it in GitHub Desktop.
r = "lala https://gist.github.com/ lele http://github.com/ lili www.google.com/ lolo"
urls = r.split(/\s+/).find_all { |u| u =~ /^https?:/ }
urls.each do |url|
r = r.gsub(url,"<a href='#{url}' target='_blank'>#{url}</a>")
end
r
-------------------------
the code above should work on irb
this regex gets urls starting with 'http' or 'https',
but I needed something quite more generic, to get www and stuff, can someone help?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment