java正则表达式获取url的host示例
发布时间:2016-12-28 来源:查字典编辑
摘要:复制代码代码如下:publicstaticStringgetHost(Stringurl){if(url==null||url.trim()...
复制代码 代码如下:
public static String getHost(String url){
if(url==null||url.trim().equals("")){
return "";
}
String host = "";
Pattern p = Pattern.compile("(?<=//|)((w)+.)+w+");
Matcher matcher = p.matcher(url);
if(matcher.find()){
host = matcher.group();
}
return host;
}