判断一个字符串中是否含有中文
public static boolean isContainsChinese(String str) { String regEx = "[\u4e00-\u9fa5]"; Pattern pat = Pattern.compile(regEx); Matcher matcher = pat.matcher(str); boolean flg = false; if (matcher.find()) { flg = true; } return flg; }
判断一个字符串是否全是中文
public static boolean isChinese(String str) { boolean flag = false; if (null == str || str.trim().length() == 0) { return flag; } String regex = "^[\u4e00-\u9fa5]*$"; flag = str.matches(regex.trim()); return flag; }原文链接:https://www.f2er.com/regex/360832.html