不要用“前缀不是/abc ,或者/bcd, 或者/efg 或者/ddy”是正确的而是反过来凡是“前缀是/abc ,或者/bcd, 或者/efg 或者/ddy”,是错误的也就是不要str.matches(sth),而是
!str.matches("^(/abc)|(/bcd)|(/efg)|(/ddy)");

解决方案 »

  1.   

    sorry那个regex写错了,
    反正我的意思就是倒过来思考问题
      

  2.   

    我这个表达式是要写在web.xml中的进行过滤器的配置的,所以只能写成一个表达式
      

  3.   

    [shine333(enihs) 的例子中,我测试了一下,/abcd是符合的[匹配的],我要的是[/abcd不匹配]
      

  4.   

    貌似/abcd不匹配阿
      public static final Pattern PATTERN = Pattern.compile("(?!/abc|/bcd).*");
      
      public static boolean match(String str) {
        Matcher matcher = PATTERN.matcher(str);
        return matcher.matches();
      }  public static void main(String[] args) throws Exception {
        System.out.println(match("/abcxyz"));
        System.out.println(match("/abc"));
        System.out.println(match("/bcd"));
        System.out.println(match("/xyz"));
        System.out.println(match("abc"));
        System.out.println(match("/abcd"));
        System.out.println(match("/ab"));
      }
      

  5.   

    shine333(enihs) 的例子改成如下就可以了:
    ^(?!/abc|/bcd)或^(?!/abc|/bcd).*
    但是不适用结尾的测试。