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
这样的正则表达式怎么写?
解决方案 »
- 关于Eclipse3.2的Myeclipse
- java 能否根据内存地址获得内存数据?
- AS/400 DB2中的中文如何转码
- java运行指定目录中.class文件的命令问题
- arraylist的简单问题
- 新手提问:ClassCastException是一个什么样的异常?
- 用jdbc连接mysql,结果在mysql读取出来的内容和mysql里面的内容不同,且有乱码,求救
- 一个奇怪的JAVA中文问题!请各位大虾指明!!!
- 如何利用Canlender或Date类知道某年某月有几天
- 同志们?如果是作APPLET或APPLETION的,和GUI 相关的 将QQ 留一下如何?大家好交流交流。
- 输出格式
- mark()方法怎么用?里面参数代表什么意思?
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");
}
}
}