刚学习正则表达式,现在有一个疑惑:
str1='OVERFLOW:   autoOVERFLOW:  auto; WIDTH: 100%; HEIGHT: 100% over      flow :auto , overflow:';
str2="OVERFLOW:   autoOVERFLOW:  auto; WIDTH: 100%; HEIGHT: 100% over      flow :auto , overflow:";
  在javascript 中
    pattern =/overflow:\s*auto|OVERFLOW:\s*auto/
  可以匹配 str1
但是到了java中
 pattern="overflow:\\s*auto|OVERFLOW:\\s*auto";
却不可以匹配str2,这是为什么啊?请高手支招,

解决方案 »

  1.   

        String str2="OVERFLOW:  autoOVERFLOW:  auto; WIDTH: 100%; HEIGHT: 100% over      flow :auto , overflow:";
        Pattern pattern=Pattern.compile("overflow:\\s*auto|OVERFLOW:\\s*auto");
        Matcher m = pattern.matcher(str2);
        if(m.find()) {
          System.out.println(m.group(0));
        }我测试了,代码没问题!
      

  2.   

    谢谢 二楼:   
        if(m.find()) {
          System.out.println(m.group(0));
        }
    我写成了:
        if(m.matches()) {
          System.out.println(m.group(0));
        }
    所以结果就处错误了,看来还是要好好研究一下方法...