作用:
1.校验字符串是否满足规则
2.在一段文本中查找满足要求的内容
package MyApi.a08regexdemo;
public class RegexDemo01 {
public static void main(String[] args) {
//只能是a b c
System.out.println("a".matches("[abc]"));
System.out.println("ab".matches("[abc][abc]"));
//不出现 a b c
System.out.println("a".matches("[^abc]"));
System.out.println("zz".matches("[^abc][^abc]"));
//a到z A到Z(包括头尾的范围)
System.out.println("zz".matches("[a-zA-Z][a-zA-Z]"));
//[a-d[m-p]] a到d,或m到p
System.out.println("a".matches("[a-d[m-p]]"));
//[a-z&&[def]] a-z和def的交集: d e f
System.out.println("a".matches("[a-z&&[def]]"));
//[a-z&&[^bc]] a-z和非bc的交集
System.out.println("a".matches("[a-z&&[^bc]]"));
//[a-z&&[^m-p]] a到z和除了m到p的交集
System.out.println("a".matches("[a-z&&[^m-p]]"));
}
}