public static void main(String[] args) {
String url1 = "http://www.xx.com";
String url2 = "w.xx.com";
String url3 = "https://www.xx.com";
String url4 = "www.baidu.com";
String url5 = "HTTPS://xx.com";
Pattern pattern = Pattern.compile("^([hH][tT]{2}[pP]://|[hH][tT]{2}[pP][sS]://|[wW]{3}.)(([A-Za-z0-9-~]+).)+([A-Za-z0-9-~\\/])+$");
System.out.println(pattern.matcher(url1).matches());
System.out.println(pattern.matcher(url2).matches());
System.out.println(pattern.matcher(url3).matches());
System.out.println(pattern.matcher(url4).matches());
System.out.println(pattern.matcher(url5).matches());
}
正则匹配 网址||URL
最新推荐文章于 2024-09-21 14:51:56 发布