Java中汉字的判断(正则表达式)
很多多汉字的判断都是在JS层做的,当然也有在业务逻辑层用Java代码实现的,如下:
public class Test {
public static boolean checkChs(String str) {
boolean mark = false;
Pattern pattern = Pattern.compile("[\u4E00-\u9FA5]");
Matcher matc = pattern.matcher(str);
StringBuffer stb = new StringBuffer();
while (matc.find()) {
mark = true;
stb.append(matc.group());
}
if (mark) {
System.out.println("匹配的字符串为:" + stb.toString());
}
return mark;
}
public static void main(String[] args) {
String str = "中国人sss0民123";
Test.checkChs(str);
}
}
Java中汉字的判断(正则表达式)
最新推荐文章于 2024-10-29 14:52:36 发布
本文介绍了一种使用Java正则表达式进行汉字匹配的方法,并提供了一个简单的示例程序,该程序可以检测并输出字符串中包含的所有汉字。
482

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



