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));
- }
- }
以上方法也实现了将大写英文,小写英文,数字,中文的互相分离。
相关推荐
IT之家 2020-03-11
graseed 2020-10-28
zbkyumlei 2020-10-12
SXIAOYI 2020-09-16
jinhao 2020-09-07
impress 2020-08-26
liuqipao 2020-07-07
淡风wisdon大大 2020-06-06
yoohsummer 2020-06-01
chenjia00 2020-05-29
baike 2020-05-19
扭来不叫牛奶 2020-05-08
hxmilyy 2020-05-11
黎豆子 2020-05-07
xiongweiwei00 2020-04-29
Cypress 2020-04-25
冰蝶 2020-04-20