question: static protected String domainFromHost ( String host ) { debugOut ( "domainFromHost(\"" + host + "\")" ) ; String domain = null ; Matcher mat ; mat = ipCapPattern . matcher ( host ) ; if ( mat . find ( ) ) { domain = mat . group ( 5 ) + "." + mat . group ( 4 ) + "." + mat . group ( 3 ) + "." + mat . group ( 2 ) ; debugOut ( "domain=\"" + domain + "\"" ) ; return domain ; } mat = tld3CapPattern . matcher ( host ) ; if ( mat . find ( ) ) { String tld = mat . group ( 2 ) ; if ( TLDLookup . isThreePartTLD ( tld ) ) { domain = mat . group ( 1 ) ; debugOut ( "domain=\"" + domain + ", tld=\"" + tld + "\"" ) ; return domain ; } } mat = tld2CapPattern . matcher ( host ) ; if ( mat . find ( ) ) { String tld = mat . group ( 2 ) ; if ( TLDLookup . isTwoPartTLD ( tld ) ) { domain = mat . group ( 1 ) ; debugOut ( "domain=\"" + domain + ", tld=\"" + tld + "\"" ) ; return domain ; } } mat = tldCapPattern . matcher ( host ) ; if ( mat . find ( ) ) { String tld = mat . group ( 2 ) ; domain = mat . group ( 1 ) ; debugOut ( "domain=\"" + domain + ", tld=\"" + tld + "\"" ) ; return domain ; } return domain ; }
target:  Extracts and returns the registrar domain portion of a host string. This funtion checks all known multi-part TLDs to make sure that registrar domain is complete. For example, if the supplied host string is "subdomain.example.co.uk", the TLD is "co.uk" and not "uk". Therefore, the correct registrar domain is not "co.uk", but "example.co.uk". If the domain string is an IP address, then the octets are returned in reverse order.