test

    doff

slkdf    

publicclass match {

 

    publicstaticvoid main(String[] args) {

        String content="c:\\ksldjfoi2932933./12/k339.dfjlk水库地块打算离开";

        String content1="4417 8119989898 9898"; //身份证号

        String pattern=".*k*";

//        boolean matches = Pattern.matches(pattern, content);

//        System.out.println("是否有"+matches);

        /**

         * \\右斜杠需要转义为规则=\\\\,每个\要加一个\转移

         * \\\\再换为字符就再转义一波就\\\\\\\\,替换成其他普通字符就没什么影响了

         */

        String replaceAll = content.replaceAll("\\\\", "\\\\\\\\");

        System.out.println(content.replaceAll("[^|^|]", "#"));

        System.out.println(content.replaceAll(".*k{1,}", "#"));

    }

 

}

posted @ 2017-05-19 15:08  永恒之蓝  阅读(149)  评论(1编辑  收藏  举报