package day02; /** * 将字符串中满足正则表达式的部分替换为给定内容 * String replaceAll(String
regex,Stirng replace) * @author Administrator * */ public class StringDemo4 {
public static void main(String[] args){ String str =
"ab123sdab4543das756as876asd"; str = str.replaceAll("\\d+", "#num#");
//"\d+",任意多个数字字符 System.out.println(str); } }
运行结果:
package day02; /** * * @author Administrator * */ public class StringDemo5 {
public static void main(String[] args) { String regex =
"(wqnmlgb|cnm|dsb|rnmb|sb|db|djb)"; String message =
"wqnmlgb!你怎么这么mei!com!你真shuai"; message = message.replaceAll(regex, "***");
System.out.println(message); } }
运行结果:
热门工具 换一换