/**
* 根据正则表达式判断字符是否为汉字
* 字符串中包含汉字时返回true
*/
public static boolean hasChinese(String value) {
// 汉字的Unicode取值范围
String regex = "[\u4e00-\u9fa5]";
Pattern pattern = Pattern.compile(regex);
Matcher match = pattern.matcher(value);
return match.find();
}
本文介绍了一种使用正则表达式判断字符串中是否包含汉字的方法。通过定义Unicode范围内的汉字字符,该方法能有效识别并返回字符串中是否存在汉字。

483

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



