一、敏感词屏蔽的方法:
public static String filterFile="" +
private static final String FILTER_WORD = filterFile.replaceAll("\r\n", "");
public static boolean filter(String filterWord ,String filterFile) {
Pattern p = Pattern.compile(FILTER_WORD );
if (p.matcher(filterWord).find())
return true;//表示含有该敏感词
else
return false;//表示不含有该敏感词
}
二、替换敏感词的方法:
private static final String REG_EX = "[`~!@#$%^&*??)+=|{}‘:;‘,\\[\\].<>/?~!@#??…??&*()—_+|{}【??★??;:”??’??,???\\\\]";
public static String filter(String str, String replacement) throws PatternSyntaxException {//str为敏感词,replacement要替换的内容
return Pattern.compile(REG_EX).matcher(str).replaceAll(replacement).trim();
}
原文地址:http://blog.csdn.net/u012408019/article/details/38731281