How to write code to decide if two host name in same domain ?
like :www.example.com
an开发者_如何学Cd login.eample.com
in same domainwww.example.com.us
and login.exmaple.com.us
in same domain x105.www.example.com
and login.example.com
in same dominand even www.example.com
and login.example.com.us
in same domain if possible
Using perl since no language was mentioned, pardon any rust...
([^.]+\.[^.]+$)
that regex would give you the domain of the first instance as a captured string ($1). You could use that captured string, if this was say perl, like this to see if they match.
$firstHostName =~ /([^.]+\.[^.]+$)/;
if ($secondHostName =~ /$1$/) {
print "same domain";
}
精彩评论