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 TypeField 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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值