public class Test {
public static void main(String[] args) throws Exception {
// 替换 将4个或4个以上的连续的数字替换成*
String str="wei232123jin234";
String ragex = "\\d{4,}";
String str1="wei232123jin234";//将4个或4个以上的连续的数字替换成*
String ragex1 = "[^(a-zA-Z)]";//过滤出字母、数字和中文的正则表达式
String newstr = "*";
String newstr1 = "";
//String s =str.replaceAll(ragex, newstr);
String s =str1.replaceAll(ragex1, newstr1);
System.out.println(s);
}
}Java正则表达式过滤出字母
最新推荐文章于 2024-08-24 04:41:28 发布
本文通过一个Java程序示例介绍了如何使用正则表达式进行字符串处理。该示例展示了如何匹配并替换特定模式的字符,如过滤非字母字符,这对于理解Java中正则表达式的使用非常有帮助。
259

被折叠的 条评论
为什么被折叠?



