最近在看正则表达式,刚好有个需求。支持多级域名
例如:http://www.leo.com.cn.win.tv/showuser?userid=123456

/**
* 取出域名
*
* @param url
* @return
*/
private String getHost(String url) {
if (Tool.isEmpty(url)) {
return "";
}
try {
Pattern p = Pattern.compile("[^//]*$?\\.(com|cn|net|org|biz|info|cc|tv)", Pattern.CASE_INSENSITIVE);
Matcher matcher = p.matcher(url);
matcher = p.matcher(url);
matcher.find();
return matcher.group();
} catch (Exception ex) {
this.logger.error("获取域名错误");
return "";
}
}