Java正则表达式识别中文
从由汉字,大小写英文,数字组成的语句中分离汉字:
public static void regxChinese() { String source = "桑德斯ABdD3ddd5222字符串转换健康康可能34f丰富4f成小写dx5kljfdsljDSknf943立即地方立即的ddd顶顶顶3"; String reg_charset = "([a-z]*)([A-Z]*)([0-9]*)([\u4E00-\u9FA5]*)"; Pattern p = Pattern.compile(reg_charset); Matcher m = p.matcher(source); String tag = "demo"; while (m.find()) { Log.d(tag,"0~~~~~~~~~~~~~~~ " + m.group(0)); Log.d(tag,"1~~~ " + m.group(1)); Log.d(tag,"2~~~ " + m.group(2)); Log.d(tag,"3~~~ " + m.group(3)); Log.d(tag,"4~~~ " + m.group(4)); } }
以上方法也实现了将大写英文,小写英文,数字,中文的互相分离。
-------
参考:
转自:http://blog.csdn.net/yuleslie/article/details/7311147