/*
替换功能
public String replaceAll(String regex,String replacement)
B:案例演示
论坛发表帖子,帖子中需要将数字替换为"*"
帖子: "我的电话号是12323345345,邮箱是43534@qq.com";
String regex ="\\d";
"我的电话号是12323345345,邮箱是43534@qq.com".replaceAll(regex,"*");
*/
public class RegexDemo6 {
public static void main(String[] args) {
//
// fun1();
String text = "我的电话号是12323345345,邮箱是43534@qq.com";
//定义 规则
String regex = "\\d";
String replaceText= text.replaceAll(regex, "*");
System.out.println(text);
System.out.println(replaceText);
}
private static void fun1() {
String s = "itcast";
String rs = s.replaceAll("[abc]", "xxxx ");
System.out.println(s);
System.out.println(rs);
}
}
|
|