String regEx = "listCategoryInfo.do?categoryId=.*";  
Pattern p = Pattern.compile(regEx);
Matcher m = p.matcher("listCategoryInfo.do?categoryId=5");

System.out.println(m.find() );   为什么输出是false?

解决方案 »

  1.   

    String regEx = "listCategoryInfo.do\\?categoryId=.*";“?”需要转义
      

  2.   

    String regEx = "listCategoryInfo.do\\?categoryId=.*";  
    Pattern p = Pattern.compile(regEx);
    Matcher m = p.matcher("listCategoryInfo.do\\?categoryId=5");依然是false
      

  3.   

    Matcher m = p.matcher("listCategoryInfo.do?categoryId=5");
    这里不需要转义,这里是普通字符串String regEx = "listCategoryInfo.do\\?categoryId=.*"; 
    Pattern p = Pattern.compile(regEx);这里是正则表达式,需要转义