如何才能准确匹配一个带有特殊符号如*的字符串?
比如, 统计一段文本里面, 字符串:13523456689*出现的次数,正则应该怎么写?
像下面这样写不对的啊:                String regEx = "13523456689*";
                Pattern p = Pattern.compile(regEx);
                Matcher m = p.matcher(strGet);
                while (m.find()){
                        count++;
//                        System.out.println(m.group());
                }

解决方案 »

  1.   

    public static void main(String[] args) {
    String regEx = "13523456689\\*";
    String s = "13523456689*kk13523456689*13523456689*kkkj13523456689*2092313523456689*(@&13523456689*";
            Pattern p = Pattern.compile(regEx);
            Matcher m = p.matcher(s);
            int count = 0;
            while (m.find()){
                    count++;
            }
            System.out.println(count);
    }*在正表中有特殊的意义,需要转换。你要记得给分啊