public static void main(String[] args) throws IOException {
String str="暴力,河岸。";
String r="[^/u4e00-/u9fa5]";
str=str.replaceAll(r,"");
System.out.println(str);
String regEx="暴力|色情"; //表示a或f
Pattern p=Pattern.compile(regEx);
Matcher m=p.matcher(str);
boolean result=m.find();
System.out.println(result);
}
字符串过滤,字符串替换(正则表达式中)去掉字符串中的非中文
最新推荐文章于 2023-01-07 10:27:41 发布
本文通过一个Java示例程序介绍了如何使用正则表达式去除字符串中的非中文字符,并演示了如何匹配特定词汇,例如检查字符串是否包含'暴力'或'色情'等敏感词。
去掉字符串中的非中文&spm=1001.2101.3001.5002&articleId=3919053&d=1&t=3&u=39e391929e5547df860ce6c687b5fdb1)
368

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



