java正则表达式应用的实例代码
程序员文章站
2024-01-12 19:04:40
string str = "n1e你v00a?az$z000?#99?9900眯2_悄s3你y4@好?!6求救你d75a8t"; pattern p= pattern.co...
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);
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);