ruby - Matching a domain with a URL -
i need check if url
match domain
ex:
http://www.opera.com/docs/changelogs/mac/ match with: opera.com
http://www.amazon.co.uk/gp/feature.html%3fie%3dutf8%26docid%3d1000423923 47 match amazon.co.uk
and so, wrote this:
require 'net/http' uri = uri('http://cran.r-url.org/bin/max/') domain = 'r-url.org' urltomatch = uri.host check = urltomatch.match(domain) if check print "match \n" else print "not match \n" end
is there better way of doing this? thank you
require 'uri' def url_on_domain?(url, domain) uri.parse(url).host.match(domain) end if url_on_domain?('http://cran.r-url.org/bin/max/', 'r-url.org') print "match \n" else print "not match \n" end
Comments
Post a Comment