Class Pattern

 
  
public final class Pattern
   
   
    
    extends 
    
    Object
   
   
   
   
    
    implements 
    
    Serializable
   
   

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 a Matcher 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();

matches 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 for repeated(反复的) matches it is less efficient(效率) since it does not allow the compiled pattern to be reused(再生).

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 the Matcher class are not safe for such use.

类的实例是不可变的,和是使用安全的通过多线程并发,Matcher类不是安全的这样使用。


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值