從由漢字,大小寫英文,數字組成的語句中分離漢字:
- 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));
- }
- }
以上方法也實現了將大寫英文,小寫英文,數字,中文的互相分離。