Skip to content

Instantly share code, notes, and snippets.

Created March 7, 2013 02:17
Show Gist options
  • Save anonymous/0bad07edf0d13fc77567 to your computer and use it in GitHub Desktop.
Save anonymous/0bad07edf0d13fc77567 to your computer and use it in GitHub Desktop.
require 'uri'
require 'cgi'
require 'pp'
#url = "http://stackoverflow.com/questions/3927495/parsing-a-complex-url-in-ruby"
url = 'http:// this is clearly not a domain but https and www also .com is here'
valid = url.match /^(http|https):\/\/|[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,6}(:[0-9]{1,5})?(\/.*)?$/ix
if valid
puts "Thats a domain "
pp valid
else
puts "I dont think that can be taken as a domain"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment