Pattern类

java.util.regex

Class Pattern

  • All Implemented Interfaces:
    Serializable


    public final class Pattern
    extends Object
    implements Serializable
    A 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 aMatcher object that can match arbitrary(任意的)character sequences against(反对) 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 matches method 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

     boolean b = Pattern.matches("a*b", "aaaaab");
    is equivalent(相等的) to the three statementsabove(上文),though(尽管) forrepeated(重复的) matches it isless efficient(更有效率的)since(因为) it does notallow(允许) the compiled pattern to bereused(重复利用).

    Instances of this class are immutable(不变的) and are safe for use by multipleconcurrent threads(并发线程). Instances of theMatcher class are not safe forsuch use(这种用途).


    Modifier and Type Field and Description
    static int CANON_EQ
    Enables canonical( 典型) equivalence.
    static int CASE_INSENSITIVE
    Enables case-insensitive matching.(不区分大小写)
    static int COMMENTS
    Permits whitespace and comments in pattern.(允许空白和注释)
    static int DOTALL
    Enables dotall mode.
    static int LITERAL
    Enables literal parsing of the pattern.
    static int MULTILINE
    Enables multiline mode.(多行模式)
    static int UNICODE_CASE
    Enables Unicode-aware case folding.
    static int UNICODE_CHARACTER_CLASS
    Enables the Unicode version of Predefined character classes and POSIX character classes.
    static int UNIX_LINES
    Enables Unix lines mode.

你可能感兴趣的:(Pattern)