Written in front: a lot of basic useless forget almost, record, slowly pick up! Multi-Inductive summary ...
Pattern:
-
Pattern
-
Extends Object
-
Implements Serializable
The compiled representation of the regular expression.
A regular expression that is specified as a string must first be compiled into an instance of this class. The resulting pattern can then be used to create an Matcher
object that, according to the regular expression, can match any
sequence of characters
. All the states involved in performing a match reside in the match, so multiple matches can share the same pattern.
Therefore, the typical invocation order is
Pattern p = pattern. compile
("A*b"); Matcher m = p. matcher
("Aaaaab"); Boolean b = M. matches
();
This class is a convenient way to define a method when you use only one regular expression matches
. This method compiles an expression and matches the input sequence in a single call. Statement
Boolean B = pattern.matches ("A*b", "Aaaaab");
is equivalent to the three statements above, although it is inefficient for duplicate matches because it does not allow the reuse of compiled schemas.
Matcher:
-
Matcher
-
Extends Object
-
Implements Matchresult
By explaining Pattern
the
engine that performs the matching operation on the character sequence.
Creates a match from a pattern by invoking the mode's matcher
method. After you create a match, you can use it to perform three different matching operations:
matches
Method attempts to match the entire input sequence to the pattern.
lookingAt
Attempts to match the input sequence to the pattern from the beginning.
find
method to scan the input sequence to find the next subsequence that matches the pattern.
Each method returns a Boolean value that represents success or failure. You can get more information about a successful match by querying the status of the match.
Typical uses are:
Welcome everybody to discuss the study together!
Useful Self-collection!
Record and share, let you and I grow together! Welcome to my other blogs, my blog address: Http://blog.csdn.net/caicongyang
Pattern\matcher Combination of Java Basics