正则表达式匹配单个汉字及多个汉字
一、匹配单个汉字方法一:利用正则表达式 [\u4e00-\u9fa5]//1.匹配单个汉字boolean flag1 = Pattern.matches("[\\u4e00-\\u9fa5]","我");System.out.println(flag1); //true方法二:利用正则表达式 [^\x00-\xff]//2.匹配单个汉字boolean flag2 = Pattern.matches
文章共427字 · 阅读需要大约2分钟
一键AI生成摘要,助你高效阅读
问答
·
一、匹配单个汉字
方法一:利用正则表达式 [\u4e00-\u9fa5]
//1.匹配单个汉字
boolean flag1 = Pattern.matches("[\\u4e00-\\u9fa5]","我");
System.out.println(flag1); //true
方法二:利用正则表达式 [^\x00-\xff]
//2.匹配单个汉字
boolean flag2 = Pattern.matches("[^\\x00-\\xff]","你");
System.out.println(flag2); //true
二、匹配多个汉字
方法一:利用正则表达式 [\u4e00-\u9fa5]+
//3.匹配多个汉字
boolean flag3 = Pattern.matches("[\\u4e00-\\u9fa5]+","我的");
System.out.println(flag3); //true
方法二:利用正则表达式 [^\x00-\xff]+
//4.匹配多个个汉字
boolean flag4 = Pattern.matches("[^\\x00-\\xff]+","你的");
System.out.println(flag4); //true
更多推荐
已为社区贡献1条内容
所有评论(0)