java正则表达式找出不包含特定字符串

来源:互联网 发布:如何装修出租屋知乎 编辑:程序博客网 时间:2024/06/05 11:39

推荐文章:http://xixian.iteye.com/blog/1323630      和http://www.jb51.net/article/52491.htm

自己的经验是不能和正常的正则表达式一起混用。

代码如下:是不能正确判断的

public class Test {
    public static void main(String[] args) {
        String url ="http://so.xywy.com/zonghe.php?keyword=ganmao=2page";
        String PdReg= "http://so.xywy.com/(zonghe|yisheng).php[?]keyword=.*^(?!.*page).*";
        Pattern p1 = Pattern.compile(PdReg);
         Matcher m = p1.matcher(url);
         System.out.println(m.matches());
    }
}


代码如下:结果是可以得

public class Test {
    public static void main(String[] args) {
        String url ="http://so.xywy.com/zonghe.php?keyword=ganmao=2page";
        String PdReg= "http://so.xywy.com/(zonghe|yisheng).php[?]keyword=.*";
        //^(?!.*page).*
        Pattern p1 = Pattern.compile(PdReg);
         Matcher m = p1.matcher(url);
         System.out.println(m.matches());
    }
}


代码如下:结果是可以得

public class Test {
    public static void main(String[] args) {
        String url ="http://so.xywy.com/zonghe.php?keyword=ganmao=2page";
        String PdReg= "^(?!.*page).*";
        //http://so.xywy.com/(zonghe|yisheng).php[?]keyword=.*
        Pattern p1 = Pattern.compile(PdReg);
         Matcher m = p1.matcher(url);
         System.out.println(m.matches());
    }
}


结论是两种形式不能混用


0 0
原创粉丝点击