How to extract URLs from text

前端 未结 6 2120
有刺的猬
有刺的猬 2020-12-03 02:56

How do I extract all URLs from a plain text file in Ruby?

I tried some libraries but they fail in some cases. What\'s the best way?

6条回答
  •  一个人的身影
    2020-12-03 03:51

    I've used twitter-text gem

    require "twitter-text"
    class UrlParser
        include Twitter::Extractor
    end
    
    urls = UrlParser.new.extract_urls("http://stackoverflow.com")
    puts urls.inspect
    

提交回复
热议问题