正则表达式对字符串的常见操作_替换

其实使用的就是String类中的replaceAll()方法。

public class RegexDemo {
    public static void main(String[] args) {

        functionDemo();
    }
    public static void functionDemo() {
        
        String str = "zhangsanttttxiaoqiangmmmmmmzhaoliu";
        
        str = str.replaceAll("(.)\1+", "$1");
        
        System.out.println(str);
        
        String tel = "15800001111";//158****1111;
        
        tel = tel.replaceAll("(\d{3})\d{4}(\d{4})", "$1****$2");
        
        System.out.println(tel);
    }
}
原文地址:https://www.cnblogs.com/LO-ME/p/3603401.html