首页 > 开发 > Java > 正文

java正则的实例应用分析

2020-02-29 20:06:10
字体:
来源:转载
供稿:网友

String str = "n1e你v00a?Az$Z000?#99?9900眯2_悄s3你y4@好?!6求救你d75a8t";
Pattern p= Pattern.compile("[/u4e00-/u9fa5]");//把汉字截取出来。
Matcher m= p.matcher(str);
while(m.find()){
System.out.print(m.group());
}

String str = "n1e你v00a?Az$Z000?#99?9900眯2_悄s3你y4@好?!6求救你d75a8t";
String a = "";
String b = "";
String d = "";
String s = "";
for(int i = 0;i char c = str.charAt(i);
if(48 a+=c;
} else if(64 b+=c;
}else if(96 b+=c;
}else{
if(((String.valueOf(c)).getBytes().length)>1){
d+=c;
}else{
s+=c;
}
}

}
System.out.println(a);
System.out.println(b);
System.out.println(d);
System.out.println(s);

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表