Class Pattern
- java.lang.Object
-
- java.util.regex.Pattern
-
-
All Implemented Interfaces:
- Serializable
public final class Pattern extends Object implements SerializableA compiled(编译) representation(表示) of a regular 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 a
Matcherobject that can match arbitrary(任意的)character sequencesagainst(反对) the regular expression. All of the stateinvolved(涉及) in performing(执行) a matchresides(存在) in the matcher, so many matchers canshare(共享) thesame(相同的) pattern.A typical(典型的) invocation(调用) sequenceis thus
Pattern p = Pattern.compile("a*b"); Matcher m = p.matcher("aaaaab"); boolean b = m.matches();A
matchesmethod is defined(定义) by this class as a convenience(方便) for when a regular expression is usedjust once(仅此一次). This method compiles an expression and matches an input sequence against it in a single invocation(调用). The statement
is equivalent(相等的) to the three statementsabove(上文),though(尽管) forrepeated(重复的) matches it isless efficient(更有效率的)since(因为) it does notallow(允许) the compiled pattern to bereused(重复利用).boolean b = Pattern.matches("a*b", "aaaaab");Instances of this class are immutable(不变的) and are safe for use by multipleconcurrent threads(并发线程). Instances of the
Matcherclass are not safe forsuch use(这种用途).Modifier and Type Field and Description static intCANON_EQEnables canonical( 典型) equivalence.static intCASE_INSENSITIVEEnables case-insensitive matching.(不区分大小写)static intCOMMENTSPermits whitespace and comments in pattern.(允许空白和注释)static intDOTALLEnables dotall mode.static intLITERALEnables literal parsing of the pattern.static intMULTILINEEnables multiline mode.(多行模式)static intUNICODE_CASEEnables Unicode-aware case folding.static intUNICODE_CHARACTER_CLASSEnables the Unicode version of Predefined character classes and POSIX character classes.static intUNIX_LINESEnables Unix lines mode.

被折叠的 条评论
为什么被折叠?



