java 正则表达式 find
public static void main(String[] args){
String s = "AaABBBBcc&^%adfsfdCCOkk998_haHA";
String pattern = "[a-z]";
Pattern p = Pattern.compile(pattern);
Matcher matcher1 = p.matcher(s);
System.out.println("字符串中的小写字母:");
while(matcher1.find()){
System.out.print(matcher1.group());
}
System.out.println();
String pattern2 = "[A-Z]";
Pattern p2 = Pattern.compile(pattern2);
Matcher matcher2 = p2.matcher(s);
System.out.println("这段字符串中的大写字母:");
while(matcher2.find()){
System.out.print(matcher2.group());
}
System.out.println();
String pattern3 = "[!@#$%^&*()_]";
Pattern p3 = Pattern.compile(pattern3);
Matcher matcher3 = p3.matcher(s);
System.out.println("符号:");
while(matcher3.find()){
System.out.print(matcher3.group());
}
}