JAVA 正则表达式 Regex

    //正则表达式,去掉空格、换行、制表位
    public static void replaceBlank(){

        Pattern p = Pattern.compile("\\s*|\t|\r|\n");

        String str="  I am a, I am Hello ok, \n new line ffdsa!";

        System.out.println("before:"+str);

        Matcher m = p.matcher(str);

        String after = m.replaceAll("");

        System.out.println("after:"+after);

    }    

 

posted on 2013-08-22 12:04  笑剑钝  阅读(250)  评论(0编辑  收藏  举报

导航