System.out.println(m2.matches());
System.out.println(m2.matches());
//所以find是在一个串中找有没有对应的模式,而matchs是完全匹配
//test lookupat()
System.out.println("test lookupat()");
Pattern p3 = Pattern.compile("a{2}");
Matcher m3 = p3.matcher("aaaa");
System.out.println(p3.flags());
System.out.println(m3.lookingAt());
System.out.println(m3.lookingAt());
System.out.println(m3.lookingAt());
//总结以上matchs()是整个匹配且总是从头开始,find是部分匹配且从上一次匹配结束时开始找
//lookingAt也是从头开始,但是部分匹配
System.out.println("======test 空白行========");
System.out.println(" \n".matches("^[ \\t]*$\\n"));
//演示appendXXX的用法
System.out.println("=================test append====================");
Pattern p4 = Pattern.compile("cat");
Matcher m4 = p4.matcher("one cat two cats in the yard");
StringBuffer sb = new StringBuffer();
boolean result = m4.find();
int i=0;
System.out.println("one cat two cats in the yard");
while(result)
{m4.appendReplacement(sb, "dog");
System.out.println(m4.group());
System.out.println("第"+i+++"次:"+sb.toString());
result = m4.find();
}
System.out.println(sb.toString());
m4.appendTail(sb);
System.out.println(sb.toString());
//test UNIX_LINES
System.out.println("test UNIX_LINES");
Pattern p5=Pattern.compile(".",Pattern.UNIX_LINES);
Matcher m5=p5.matcher("\n\r");
System.out.println(m5.find());
System.out.println(m5.find());
//test UNIX_LINES
System.out.println("test UNIX_LINES");
Pattern p6=Pattern.compile("( d).");
Matcher m6=p6.matcher("\n\r");
System.out.println(m6.find());
System.out.println(m6.find());
//test UNIX_LINES
System.out.println("test UNIX_LINES");
Pattern p7=Pattern.compile(".");
Matcher m7=p7.matcher("\n\r");
System.out.println(m7.find());
System.out.println(m7.find());
//test CASE_INSENSITIVE
System.out.println("test CASE_INSENSITIVE");
Pattern p8=Pattern.compile("a",Pattern.CASE_INSENSITIVE);
Matcher m8=p8.matcher("aA");
System.out.println(m8.find());
System.out.println(m8.find());
System.out.println("test CASE_INSENSITIVE");
Pattern p9=Pattern.compile("( i)a");
Matcher m9=p9.matcher("aA");
System.out.println(m9.find());
System.out.println(m9.find());
System.out.println("test CASE_INSENSITIVE");
Pattern p10=Pattern.compile("a");
Matcher m10=p10.matcher("aA");
System.out.println(m10.find());
System.out.println(m10.find());
//test COMMENTS
System.out.println("test COMMENTS");
Pattern p11=Pattern.compile(" a a #ccc",Pattern.COMMENTS);
Matcher m11=p11.matcher("aa a a #ccc");
System.out.println(m11.find());
System.out.println(m11.find());
System.out.println("test COMMENTS");
Pattern p12 = Pattern.compile("( x) a a #ccc");
Matcher m12 = p12.matcher("aa a a #ccc");
System.out.println(m12.find());
System.out.println(m12.find());
//test MULTILINE这个大家多试试参照我上面对多行模式的理解
System.out.println("test MULTILINE");
Pattern p13=Pattern.compile("^. ",Pattern.MULTILINE|Pattern.DOTALL);
Matcher m13=p13.matcher("helloohelloo,loveroo");
System.out.println(m13.find());
System.out.println("start:"+m13.start()+"end:"+m13.end());
System.out.println(m13.find());
//System.out.println("start:"+m13.start()+"end:"+m13.end());
System.out.println("test MULTILINE");
Pattern p14=Pattern.compile("( m)^hell.*oo$",Pattern.DOTALL);
Matcher m14=p14.matcher("hello,Wor