public final class Pattern
A compiled(编译)representation(表演)of aregular(正常的)expression(表示).
一个正则表达式演示
A regular expression, specified as a string, must first be compiled into an instance of this class. The resulting pattern can then be used to create aMatcher
object that can match arbitrary(随意的)character sequences
against the regular expression. All of the stateinvolved(参与)inperforming(执行)a match resides in the matcher, so many matchers can share the same pattern.
一个正则表达式 ,指定了一个string,必须第一个被编译到这个类的实例中。
pattern的结果能被创建给一个matcher对象,和match能匹配任意字符顺序通过正则表达式
所有的执行匹配在matcher,所以许多matcher能共享相同的patter
A typical(典型的)invocation sequence is thus
Pattern p = Pattern.compile
("a*b"); Matcher m = p.matcher
("aaaaab"); boolean b = m.matches
();
Amatches
method isdefined(定义)by this class as a convenience(方便的)for when a regular expression is used just once. This method compiles anexpression(表达式)and matches an input sequence against it in a single invocation. is equivalent to the three statements above, though forrepeated(反复的)matches it is lessefficient(效率)since it does not allow the compiled pattern to bereused(再生).
matches这方法是由这个类定义的,当正则表达式被使用仅一次。
这方法编译一个表达式和有顺序的单个匹配,
boolean b = Pattern.matches("a*b", "aaaaab");
is equivalent(相等的)to the three statements above, though for repeated(反复的)matches it is less efficient(效率)since it does not allow the compiled pattern to be reused(再生).
它返回的三次了,由于反复的匹配它是低效率的自从它不允许重新编译。
Instances of this class are immutable(不变)and are safe for use by multiple concurrent threads. Instances of theMatcher
class are not safe for such use.
类的实例是不可变的,和是使用安全的通过多线程并发,Matcher类不是安全的这样使用。