url1: http://www.xxx.com/aaa/bbb/1.html
url2: http://www.xxx.com/aaa/bbb
url3: http://www.xxx.com/ccc.jpg
url4: http://www.xxx.com/ddd.css
用正则匹配以上四种url,只获取url1和url2,不要url3和url4
这样的正则表达式怎么写?
url2: http://www.xxx.com/aaa/bbb
url3: http://www.xxx.com/ccc.jpg
url4: http://www.xxx.com/ddd.css
用正则匹配以上四种url,只获取url1和url2,不要url3和url4
这样的正则表达式怎么写?
url::http://([\w-]+\.)+[\w-]+(/[\w- ./?%&=]*)?
[21:06:08.125] org.tuckey.web.filters.urlrewrite.Conf DEBUG: about to parse conf
[21:06:08.126] org.tuckey.web.filters.urlrewrite.ConfHandler DEBUG: Resolving to DTD /org/tuckey/web/filters/urlrewrite/dtds/urlrewrite3.2.dtd
[21:06:08.135] org.tuckey.web.filters.urlrewrite.ConfHandler DEBUG: error: expected name at `='
[21:06:08.143] org.tuckey.web.filters.urlrewrite.Conf ERROR: Exception loading conf file:/E:/Project/GIP4/V4.5.0/WebRoot/WEB-INF/urlrewrite.xml:6: expected name at `='
[21:06:08.143] com.caucho.xml.XmlParseException: file:/E:/Project/WebRoot/WEB-INF/urlrewrite.xml:6: expected name at `='
[21:06:08.143] at com.caucho.xml.XmlParser.error(XmlParser.java:2958)
只要结尾时html的,或者什么都没有的,不要其他的。
//package com.ricky.www;
import java.util.regex.Pattern;
import java.util.regex.Matcher;/*
url1: http://www.xxx.com/aaa/bbb/1.html
url2: http://www.xxx.com/aaa/bbb
*/public class Test{
public static void main(String[] args){
String url1 = "http://www.xxx.com/aaa/bbb/1.html";
String url2 = "http://www.xxx.com/aaa/bbb";
test(url1);
test(url2);
} public static void test(String url){
//^https?://[\\w_]+(\\.[\\w_]+)*(\\.html)?$
String regex = "^https?://[\\w_]+(\\.[\\w_]+)*(/[\\w_]+)*(\\.html)?$";
Pattern pattern = Pattern.compile(regex);
Matcher matcher = pattern.matcher(url);
if(matcher.matches()){
System.out.println("true");
}else{
System.out.println("false");
}
}
}