1

How can I use the code bellow to check if the domain is a real match.

For that domain and url is going to return true, but is going to work for this url = http://www.text-apple.com/uk/ to, which is not a true match.

But it should be a match in this case url = http://itunes.apple.com", so i need to add something like if there is a . before the domain name then is a match.

domain = "apple.com"
url = "http://www.apple.com/uk/"

def domain_is_URL?(url, domain)
 d = Regexp.escape(domain)
 URI.parse(url).host.match(d)
end

Thank you

4

2 回答 2

2

您可以尝试比较主机组件:

domain_parts = domain.split('.')

URI.parse(url).host.split('.').last(domain_parts.length) == domain_parts.length

这会比较 URI 主机的最后 N 部分,看看它们是否相同。[ 'text-apple', 'com' ]不等于[ 'apple', 'com' ]

于 2013-10-11T14:52:46.927 回答
0

您可以尝试使用基数树来构建您的域列表,然后根据基数树评估您的部分 URL。

于 2018-07-27T07:09:51.597 回答