xjzhang1_13
xjzhang1_13
采纳率0%
2017-05-18 03:01 浏览 2.8k

正则表达式匹配URL中的访问资源

3

java语言编写,匹配URL中的访问资源,不匹配后面的参数,正则表达式怎么写?
"GET /SchoolClubManage/jsp/common/applyjoinclub.html?name=../../../../../../../../../../etc/passwd%00.jpg HTTP/1.1" 200 5953
这条记录只匹配/SchoolClubManage/jsp/common/applyjoinclub.html?

"GET /SchoolClubManage/font/ HTTP/1.1" 200 3216
这条记录只匹配 /SchoolClubManage/font

多谢,急急急

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

3条回答 默认 最新

  • FluxMode FluxMode 2017-05-18 03:03

    可以不用正则,使用这个IndexOf()吗

    点赞 评论 复制链接分享
  • beyondlfover beyondSelf 2017-05-18 03:07
     PathMatcher matcher = new AntPathMatcher()
     String uri = "/user/rest/isc/user/UUID1238weqw123";
     String pattern = "/user/rest/isc/user/**";
     matcher.match(pattern, uri);
    
    点赞 评论 复制链接分享
  • a350062174 a350062174 2017-05-20 06:39

    Pattern p = Pattern.compile("/SchoolClubManage/.*?[\? ]");
    Matcher m= p.matcher("GET /SchoolClubManage/jsp/common/applyjoinclub.html?name=../../../../../../../../../../etc/passwd%00.jpg HTTP/1.1\" 200 5953");
    if(m.find()){
    System.out.println(m.group());
    }

    点赞 评论 复制链接分享

相关推荐