Skip to content

Instantly share code, notes, and snippets.

@hanssens
Created October 31, 2014 11:51
Show Gist options
  • Save hanssens/9799240d3a9064c1c87e to your computer and use it in GitHub Desktop.
Save hanssens/9799240d3a9064c1c87e to your computer and use it in GitHub Desktop.
Reads a file and extracts all url's from it.
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