import java.util.regex.*;public class A{
public static void main( String[] args ){
String str = "http://sports.sina.com.cn";
Pattern p = Pattern.compile( "http://[\\w\\-]*?\\.(.*?)(\\..*?)+", Pattern.CASE_INSENSITIVE );
Matcher m = p.matcher( str );
String domain;
if (m.find()) {
domain = m.group(1);
} else {
domain = "XXX";
}
System.out.println( domain );
}
}
OK?
public static void main( String[] args ){
String str = "http://sports.sina.com.cn";
Pattern p = Pattern.compile( "http://[\\w\\-]*?\\.(.*?)(\\..*?)+", Pattern.CASE_INSENSITIVE );
Matcher m = p.matcher( str );
String domain;
if (m.find()) {
domain = m.group(1);
} else {
domain = "XXX";
}
System.out.println( domain );
}
}
OK?
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货