正则表达式简单应用3

1,public class replaceDemo {
    public static void main(String[] args) {
        String old_str = "Hello563413Java12345621HelloWorld";
        String regex = "\\d";
        //屏蔽掉数字
        String new_str = old_str.replaceAll(regex, "*");
        System.out.println(new_str);
    }
}

2,public class replaceTest {
public static void main(String[] args) {
    String st = "liffffffuzddddekuagggggggggn";
    //正则中组的应用
    String[] str = st.split("(.)\\1+");
    for(String st1:str){
        System.out.print(st1);//liuzekuan
    }
    //需求:177****5997
    System.out.println();
    String str2= "17756595997";
    //相对替换
    str2 = str2.replaceAll("(\\d{3})(\\d{4})(\\d{4})","$1****$3");
    System.out.println(str2);

}}
posted @ 2016-11-14 19:14  第五个世界  阅读(71)  评论(0编辑  收藏  举报