对String字符串进行修改
package day_160810_regex;
import java.util.Arrays;
public class Demo02 {
public static void main(String[] args) {
String s = "1,2,3,4,5";
String[] ss = s.split(",");
System.out.println(Arrays.toString(ss));
// ip
s = "192.168.1.168";
ss = s.split("\\.");
System.out.println(Arrays.toString(ss));
// 2017-11-21 14:30:20
s = "2017-11-21 14:30:20";
ss = s.split("[-:]");
System.out.println(Arrays.toString(ss));
// 根据数字进行拆分
s = "d211fjkdfjkd323fkd32j35klak5dfjldkfj";
// ss=s.split("\\d{1,}");或者
ss=s.split("\\d+");
System.out.println(Arrays.toString(ss));
//根据叠词进行拆分
s="1234555556789qw--ertyyyyyuioasdffffghjklzjjjxcvbnnnnnm";
ss=s.split("(.)\\1+");
System.out.println(Arrays.toString(ss));
//将数字替换成*
String a="qwe1234rtyui456oasdfgh67jzxc892vbn";
a=a.replaceAll("\\d+", "*");
System.out.println(a);
//将叠词换成1
a="1234555556789qw--ertyyyyyuioasdffffghjklzjjjxcvbnnnnnm";
a=a.replaceAll("(.)\\1+", "1");
System.out.println(a);
//将叠词去掉剩一个,将..去掉
a = "我我..我我..我.们们们...们们..去去去去去..去去....去去..."
+ "吃吃...吃吃吃吃..吃饭饭.饭...饭饭饭..吧吧吧吧吧" + "吧...吧吧..吧吧吧...,你你....请请.请"
+ "请请...请.客客客..客..客";
a=a.replaceAll("\\.", "");
System.out.println(a);
a=a.replaceAll("(.)\\1+", "$1");
System.out.println(a);
}
}