public static void main(String[] args) {
String s = "aaaa......bbbb....ccc...dddddd";
String s2 = s.replaceAll("\\.+","");
System.out.println(s2); // s2:aaaabbbbcccdddddd
String s3 = s2.replaceAll("(.)\\1+","$1"); // $1代表第一组中的内容
System.out.println(s3); //s3:abcd
}