IpUtils { public static String extractDomain(String url) { if (isEmpty(url)) return null; int len = url.split("/").length; Matcher m; if (len < 3) { _log.error(String.format("URL[%s] is invalid!", url)); return null; } else if (len > 3) { if ((m = EXTRACT_DOMAIN_WITH_SUB_PATH.matcher(url)).find()) return m.group(0); } else { if (!url.endsWith("/")) m = EXTRACT_DOMAIN_SIMPLE.matcher(url); else m = EXTRACT_DOMAIN_SIMPLE_END_WITH_TAIL.matcher(url); if (m.find()) return m.group(0); } return null; } private  IpUtils(); static boolean checkValid(final String ip); static boolean checkValid2(final String ip); static boolean checkValidV6(final String ip); static String removeTail32(String ip); static String extractDomain(String url); static String getTailFromURL(String url); static long ip2long(String ipAddress); static String long2ip(Long ipAddress); static Integer ip2int(String ipAddress); static Boolean checkIPRange(final String ipAddress, final String range); static String getIPFromURL(String url); static Boolean isReachable(final String ipAddress); static boolean ping(final String ipAddress); static List<String> getCurrentEnvironmentNetworkIps();  }
@Test public void extractDomainTest() { assertEquals("yuzhouwan.com", extractDomain("https: assertEquals("yuzhouwan.com", extractDomain("https: assertEquals("yuzhouwan.com", extractDomain("https: assertNull(extractDomain("http:/yuzhouwan.com")); assertNull(extractDomain("")); assertNull(extractDomain(null)); }