在JDK中的正则引擎主要有五个类:ASCII.class Pattern.class Matcher.clas matchResult.class PatternSyntaxException.class
关键的是Pattern和Matcher类。
正则表达式必须首先被编译为Pattern类的一个实例。 然后才能生成一个对象去匹配任意的字符。
编译方法: public static Pattern compile(String regex) {
return new Pattern(regex, 0);
}
将regex编译到pattern里。
Matcher是一个引擎类,它通过解释执行pattern类,来对字符队列进行匹配操作。
pattern类通过调用public Matcher matcher(CharSequence input) 来触发引擎类。返回一个Matcher对象。