Created
November 5, 2010 19:37
-
-
Save th1agoalmeida/664654 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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