如何在 Ruby 中从纯文本文件中提取所有 URL?
我尝试了一些库,但在某些情况下它们会失败。最好的办法是什么?
如果您喜欢使用 Ruby 中已提供的功能:
require "uri"
URI.extract("text here http://foo.example.org/bla and here mailto:[email protected] /cdn-cgi/l/email-protection and here also.")
# => ["http://foo.example.org/bla", "mailto:[email protected] /cdn-cgi/l/email-protection"]
阅读更多:http://railsapi.com/doc/ruby-v1.8/classes/URI.html#M004495 http://railsapi.com/doc/ruby-v1.8/classes/URI.html#M004495
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)