I am creating a bookmarking site. I want to extract all URIs / links from email. My site uses Ruby on Rails.
How to extract all urls of received email content?
Ruby's built-in URI does this already:
From extractdocs:
extract
require "uri" URI.extract("text here http://foo.example.org/bla and here mailto:test@example.com and here also.") # => ["http://foo.example.com/bla", "mailto:test@example.com"]
require 'uri' text = %{"test <a href="http://www.a.com/">http://www.a.com/</a>, and be sure to check http://www.a.com/blog/. Email me at <a href="mailto:b@a.com">b@a.com</a>.} END_CHARS = %{.,'?!:;} p URI.extract(text, ['http']).collect { |u| END_CHARS.index(u[-1]) ? u.chop : u }
Source: http://www.java2s.com/Code/Ruby/Network/ExtractURL.htm