表达式
【(ftp|http|https)://([-A-Za-z0-9+&@#/%?=~_|!:,.;]+[-A-Za-z0-9+&@#/%=~_|]):([0-9]*)/(.*)】
解析字符串”ftp://10.1.8.198:2121/test.zip“
Pattern p = Pattern.compile("(ftp)://([-A-Za-z0-9+&@#/%?=~_|!:,.;]+[-A-Za-z0-9+&@#/%=~_|]):([0-9]*)/(.*)");
Matcher m= p.matcher("ftp://10.1.8.198:2121/test.zip");
if(m.find()){
System.out.println(m.group(1));
System.out.println(m.group(2));
System.out.println(m.group(3));
System.out.println(m.group(4));
}
打印结果为
ftp
10.1.8.198
2121
test.zip