利⽤正则表达式,对String对象进⾏替换与分割对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.String(ss));
// ip
s = "192.168.1.168";
ss = s.split("\\.");
System.out.String(ss));
// 2017-11-21 14:30:20
s = "2017-11-21 14:30:20";
ss = s.split("[-:]");
System.out.String(ss));
// 根据数字进⾏拆分
s = "d211fjkdfjkd323fkd32j35klak5dfjldkfj";
// ss=s.split("\\d{1,}");或者
ss=s.split("\\d+");
System.out.String(ss));
//根据叠词进⾏拆分
s="1234555556789qw--ertyyyyyuioasdffffghjklzjjjxcvbnnnnnm";
ss=s.split("(.)\\1+");
System.out.String(ss));
//将数字替换成*
String a="qwe1234rtyui456oasdfgh67jzxc892vbn";
placeAll("\\d+", "*");
System.out.println(a);
//将叠词换成1
a="1234555556789qw--ertyyyyyuioasdffffghjklzjjjxcvbnnnnnm";
placeAll("(.)\\1+", "1");
System.out.println(a);
/
/将叠词去掉剩⼀个,将..去掉
a = "我我..我我..我.们们们...们们..去去去去去..去去....去去..."
+ "吃吃...吃吃吃吃..吃饭饭.饭...饭饭饭..吧吧吧吧吧" + "吧...吧吧..吧吧吧...,你你....请请.请"
+ "请请...请.客客客..客..客";
placeAll("\\.", "");
replaceall()System.out.println(a);
placeAll("(.)\\1+", "$1");
System.out.println(a);
}
}
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论