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 java.lang.CharSequence 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
java
Pattern p = Pattern.compile("a*b");Matcher m = p.matcher("aaaaab");boolean b = m.matches();
/* * This private constructor is used to create all Patterns. The pattern * string and match flags are all that is needed to completely describe * a Pattern. An empty pattern string results in an object tree with * only a Start node and a LastNode node. */private Pattern(String p, int f) { ... }// ...public static Pattern compile(String regex) { return new Pattern(regex, 0);}public static Pattern compile(String regex, int flags) { return new Pattern(regex, flags);}
2๊ฐ์ ์ ์ผํ ์ง๋ ฌํ ์์: the pattern string and the flags
[!quote] Docs
java
/** A regular expression, specified as a string, must first be compiled into an instance of this class.** Pattern has only two serialized components: The pattern string* and the flags, which are all that is needed to recompile the pattern* when it is deserialized*/
/* * An engine that performs match operation on a java.lang.CharSequence character sequence by interpreting a Pattern. * * A matcher is created from a pattern by invoking the pattern's Patter#matcher matcher method. (...) */public final class Matcher implements MatchResult { Matcher() {} // No default constructor. /** * All matchers have the state used by Pattern during a match. */ Matcher(Pattern parent, CharSequence text) { ... )