System.out.println("==========================");
System.out.println("b".matches("[abc]"));
//[a-d[f-h]]==[a-df-h]
System.out.println("[a-d[f-h]]==[a-df-h]"+"h".matches("[a-d[f-h]]"));
System.out.println("a".matches("[a-z&&[def]]"));
//取交集
System.out.println("取交集"+"a".matches("[a-z&&[def]]"));
System.out.println("b".matches("[[a-z]&&[e]]"));
//取并
System.out.println("取并"+"9".matches("[[a-c][0-9]]"));
//[a-z&&[^bc]]==[ad-z]
System.out.println("[a-z&&[^bc]]==[ad-z]"+"b".matches("[a-z&&[^bc]]"));
System.out.println("d".matches("[a-z&&[^bc]]"));
//[a-z&&[^m-p]]==[a-lq-z]
System.out.println("[a-z&&[^m-p]]==[a-lq-z]"+"d".matches("[a-z&&[^m-p]]"));
System.out.println("a".matches("\\p{Lower}"));
///注意以下体会\b的用法(注意,在字符串常量中十目直接写\b表退格,所以要写\\b
System.out.println("*********************************");
System.out.println("aawordaa".matches(".*\\bword\\b.*"));
System.out.println("a word a".matches(".*\\bword\\b.*"));
System.out.println("aawordaa".matches(".*\\Bword\\B.*"));
System.out.println("a word a".matches(".*\\Bword\\B.*"));
System.out.println("a word a".matches(".*word.*"));
System.out.println("aawordaa".matches(".*word.*"));
//体会一下组的用法
//组的顺序,只数"("第一个为第一组第二个是第二组……
//第0组表示整个表达式 www.2cto.com
System.out.println("**************test group**************");
Pattern p = Pattern.compile("(([abc]+)([123]+))([-_%]+)");
Matcher m = p.matcher("aac212-%%");
System.out.println(m.matches());
m = p.matcher("cccc2223%_%_-");
System.out.println(m.matches());
System.out.println("======test group======");
System.out.println(m.group());
System.out.println(m.group(0));
System.out.println(m.group(1));
System.out.println(m.group(2));
System.out.println(m.group(3));
System.out.println(m.groupCount());
System.out.println("========test end()=========");
System.out.println(m.end());
System.out.println(m.end(2));
System.out.println("==========test start()==========");
System.out.println(m.start());
System.out.println(m.start(2));
//test backslash测试反向引用?
Pattern pp1=Pattern.compile("(\\d)\\1");//这个表达式表示必须有两相同的数字出现
//\1表示引用第一个组\n表示引用第n个组(必须用\\1而不能用\1因\1在字符串中另有意义(我也知道是什么)
Matcher mm1=pp1.matcher("3345");//33匹配但45不匹配
System.out.println("test backslash测试反向引用");
System.out.println(mm1.find());
System.out.println(mm1.find());
//体会以下不同
System.out.println("==============test find()=========");
System.out.println(m.find());
System.out.println(m.find(2));
System.out.println("这是从第三个字符(index=2)开始找的group结果");
System.out.println(m.group());
System.out.println(m.group(0));
System.out.println(m.group(1));
System.out.println(m.group(2));
System.out.println(m.group(3));
m.reset();
System.out.println(m.find());
//测试一个模式可多次匹配一个串
System.out.println("测试一个模式可多次匹配一个串");
Pattern p1 = Pattern.compile("a{2}");
Matcher m1 = p1.matcher("aaaaaa");
//这说明Matcher的matchs()方法是对事个字符串的匹配,
System.out.println(m1.matches());
System.out.println(m1.find());
System.out.println(m1.find());
System.out.println(m1.find());
System.out.println(m1.find());
//再测试matchs()
System.out.println("再测试matchs()");
Pattern p2 = Pattern.compile("(a{2})*");
Matcher m2 = p2.matcher("aaaa");
System.ou