如何使用Ruby on Rails从电子邮件中提取所有URls /链接?

我正在建立一个书签网站。 我想从电子邮件中提取所有URI /链接。 我的网站正在使用Ruby on Rails。

如何提取收到的电子邮件内容的所有url?

Ruby的内置URI模块已经实现了这一点:

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 http://www.a.com/, and be sure to check http://www.a.com/blog/. Email me at b@a.com.} END_CHARS = %{.,'?!:;} p URI.extract(text, ['http']).collect { |u| END_CHARS.index(u[-1]) ? u.chop : u } 

资料来源: http : //www.java2s.com/Code/Ruby/Network/ExtractURL.htm