public class test { public static void main(String args[]) { System.out.println("http://www.aaa.com/bbb/123/345.htm".split("/")[2]); } } 输出 www.aaa.com
String s = "http://www.aaa.com/bbb/123/345.htm"; Pattern p = Pattern.compile("(?<=http://)[^/]*(?=/)"); Matcher m = p.matcher(s); while(m.find()){ System.out.println(m.group()); }
public static void main(String[] args) { String url = "http://www.aaa.com/bbb/123/345.htm"; Matcher m = Pattern.compile("^http://[^/]+").matcher(url); while(m.find()){ System.out.println(m.group()); } }
public static void main(String[] args) { String str = "http://www.aaa.com/bbb/123/345.htm"; String s = str.replaceAll("http://(.+?)/.*", "$1"); System.out.println(s); }
System.out.println("http://www.aaa.com/bbb/123/345.htm".split("/")[2]);
}
}
输出
www.aaa.com
Pattern p = Pattern.compile("(?<=http://)[^/]*(?=/)");
Matcher m = p.matcher(s);
while(m.find()){
System.out.println(m.group());
}
public static void main(String[] args) {
String url = "http://www.aaa.com/bbb/123/345.htm";
Matcher m = Pattern.compile("^http://[^/]+").matcher(url);
while(m.find()){
System.out.println(m.group());
}
}
public static void main(String[] args) {
String str = "http://www.aaa.com/bbb/123/345.htm";
String s = str.replaceAll("http://(.+?)/.*", "$1");
System.out.println(s);
}