java正则表达式应用的实例代码

 更新时间:2008年10月01日 00:12:50   作者:  
java正则的实例应用分析,大家从下面的代码中,就能知道java正则的应用与写法
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<str.length();i++){
char c = str.charAt(i);
if(48<=c && c<=58){
a+=c;
} else if(64<=c && c<=91){
b+=c;
}else if(96<=c && c<=123){
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);

相关文章

最新评论