Created
October 31, 2014 11:51
-
-
Save hanssens/9799240d3a9064c1c87e to your computer and use it in GitHub Desktop.
Reads a file and extracts all url's from it.
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
require 'open-uri' | |
require 'uri' | |
# start off by reading the file | |
text = "" | |
File.open("whatever.txt", "r") do |f| | |
f.each_line do |line| | |
text << line | |
end | |
end | |
# extract all links from the text | |
list_of_urls = text.split(/\s+/).find_all { |u| u =~ /^https?:/ } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment