java正则表达式-语法规则学习:
public class RegExp03 {
public static void main(String[] args){
String content = "a11bcd!2_c32de BCDe";
//String resStr = "[a-z]"; //匹配a-z之间任意一个字符
//String resStr = "[A-Z]"; //匹配A-Z之间任意一个字符
//String resStr = "[abc]"; //匹配abc字符串[默认区分大小写]
//String resStr = "[(?i)abc]"; //匹配abc字符串(不区分大小写)
//(?i):表示不区分大小写 等价于Pattern.CASE_INSENSITIVE
//String resStr = "[0-9]"; //匹配0-9之间任意一个字符
//String resStr = "\\d"; //匹配0-9之间任意一个字符
//String resStr = "\\D"; //匹配不在0-9之间任意一个字符
//String resStr = "\\w"; //匹配大小写英文字母,数字,下划线
//String resStr = "\\W"; //匹配 等价于[^a-zA-Z0-9_]
//String resStr = "\\s"; //匹配任何空白字符(空格,制表符)
String resStr = "\\S"; //匹配任何非空白字符,和\\s相反
//1.构造模式对象Pattern
//Pattern pattern = Pattern.compile(resStr,Pattern.CASE_INSENSITIVE);
Pattern pattern = Pattern.compile(resStr);
//2.创造匹配器对象Matcher
Matcher matcher =pattern.matcher(content);
while (matcher.find()){
System.out.println("找到:"+matcher.group(0));
}
}
}