如何判断一个字符串是否全为汉字
2个回答
展开全部
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class test {
public static void main(String[] args) {
int count = 0;
String regEx = "[\\u4e00-\\u9fa5]";
// System.out.println(regEx);
String str = "Internet 网络 is 真好 very good ^_^!";
// System.out.println(str);
Pattern p = Pattern.compile(regEx);
Matcher m = p.matcher(str);
System.out.print("提取出来的中文有:");
while (m.find()) {
System.out.print(m.group(0)+" ");
}
System.out.println();
System.out.println(p.matches(regEx, "中"));
System.out.println(p.matches(regEx, "a"));
}
import java.util.regex.Pattern;
public class test {
public static void main(String[] args) {
int count = 0;
String regEx = "[\\u4e00-\\u9fa5]";
// System.out.println(regEx);
String str = "Internet 网络 is 真好 very good ^_^!";
// System.out.println(str);
Pattern p = Pattern.compile(regEx);
Matcher m = p.matcher(str);
System.out.print("提取出来的中文有:");
while (m.find()) {
System.out.print(m.group(0)+" ");
}
System.out.println();
System.out.println(p.matches(regEx, "中"));
System.out.println(p.matches(regEx, "a"));
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询