http://www.a.b/asd/web/ccs/jd.html
jsp/w/asd/resefo/ccs/jd.html
dfe/asd/oijs/ccs/jd.html求一个正则表达式,能匹配到其中/asd/*/ccs/jd.html部分的内容
这个正则该怎么写呀?
正则表达式还真是不懂呀!
jsp/w/asd/resefo/ccs/jd.html
dfe/asd/oijs/ccs/jd.html求一个正则表达式,能匹配到其中/asd/*/ccs/jd.html部分的内容
这个正则该怎么写呀?
正则表达式还真是不懂呀!
/符号不需要转译的吧至少没提示
还是给你个链接吧
写成:
asd/*/ccs/jd.html
asd/\\w+/ccs/jd.html
asd/\\s+/ccs/jd.html
[asd/]{1}\\w+[/ccs/jd.html]{1}
然后使用String.matches()和使用Pattern.matchers(r,s)返回的都是false
返回false是正常的,LZ还没有了解正式吧
你用Pattern.matchers(r,s)这个是能匹配到其中/asd/*/ccs/jd.html部分的内容
但是因为不是全匹配,只是能匹配到其中部分,那肯定不会返回true
如果LZ要匹配到其中/asd/*/ccs/jd.html部分的内容
可以这样 Pattern p = Pattern.compile("asd/\\w+/ccs/jd.html");
Matcher m = p.matcher(st1);
System.out.println(m.matches());
while(m.find()){
System.out.println(m.group());
}这样输出的就是LZ要的