检测出中文汉字但不检测中文标点,一般都只用这个即可
/**
* 检测出中文汉字但不检测中文标点
* @author A乐神
* date 2023/12/15
* @param str :需处理得字段
* @return boolean
**/
public static boolean isContainChinese(String str) {
Pattern p = Pattern.compile("[\u4e00-\u9fa5]");
Matcher m = p.matcher(str);
return m.find();
}
检测出中文汉字而且还检测中文标点
/**
* 检测出中文汉字而且还检测中文标点
* @author A乐神
* date 2023/12/15
* @param str :需处理得字段
* @return boolean
**/
public static boolean isContainChineseInfo(String str) {
if (StringUtils.isEmpty(str)) {
throw new RuntimeException("sms context is empty!");
}
Pattern p = Pattern.compile("[\u4E00-\u9FA5|\\!|\\,|\\。|\\(|\\)|\\《|\\》|\\“|\\”|\\?|\\:|\\;|\\【|\\】]");
Matcher m = p.matcher(str);
return m.find();
}