java判断字符串中是否有汉字并提取所有汉字部分

import java.util.regex.Matcher;
import java.util.regex.Pattern;


public class ChineseUtil {
	private static String regEx = "[\u4e00-\u9fa5]+"; 
	public static void main(String[] args) {
		String str = "abc123ABC叶诚123挨提践男";
		if(checkChineseCharacter(str))
		{
			System.out.println(returnChineseCharacter(str));
		}
	 
	}
	
	public static boolean checkChineseCharacter(String str)
	{
		if(str.getBytes().length == str.length())
			return false;
		return true;
	}
	
	public static String returnChineseCharacter(String str)
	{
		Pattern p = Pattern.compile(regEx); 
		Matcher m = p.matcher(str);
		String chiResult = "";
		while (m.find()) {
		    chiResult += m.group();
		}
		return chiResult;
	}

}



版权声明:本文为XZG1573623031原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。