Java Pattern 翻译_JAVA_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > JAVA > Java Pattern 翻译

Java Pattern 翻译

 2012/5/10 10:41:07  as619864232  程序员俱乐部  我要评论(0)
  • 摘要:java.util.regexClassPatternjava.lang.Objectjava.util.regex.PatternAllImplementedInterfaces:SerializablepublicfinalclassPatternextendsObjectimplementsSerializableAcompiled(编辑)representation(描述)ofaregularexpression(正则表达式).Aregularexpression(正则表达式)
  • 标签:翻译 Java

java.util.regex

Class Pattern

java.lang.Object
  java.util.regex.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 a Matcher object that can match arbitrary(任意)?character sequences against(违反)?the regular expression(正则表达式). All of the state involved(涉及) in performing(执行) a match(匹配)?resides(存在) in the matcher, so many matchers can share the same pattern.

A typical(典型的) invocation(调用) sequence is 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 used just 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 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.?

发表评论
用户名: 匿名