Brief introduction:
Java.util.regex is a class library package that uses patterns that are customized by regular expressions to match strings.
It consists of two classes: pattern and Matcher
Pattern |
A pattern is a compiled representation of a regular expression. |
Matcher |
A Matcher object is a state machine that expands the matching check for strings based on pattern objects as match patterns. |
First, a pattern instance is used to order a compiled schema of a similar regular expression in Perl, followed by a Matcher instance that matches the string under the mode control of the given pattern instance.
Let's take a look at these two classes separately:
Pattern class:
The pattern method is as follows:
static pattern |
compile (String regex) Compiles and assigns the given regular expression to the pattern class |
static Pattern |
compile (String regex, int flags) Ditto, but increases the specified flag parameter, optional flag parameters include: case Insensitive,multiline,dotall,unicode case, CANON EQ |
int |
flags () Returns the matching flag parameter for the current pattern. |
matcher |
matcher (Charsequenc e input) Generate a given named Matcher object |
matches (String regex, charsequence input) Compiles a given regular expression and matches the input string with the regular expression, which is appropriate for the case where the regular expression is used only once, that is, only one matching operation Because there is no need to generate a Matcher instance in this case. |
pattern () Returns the PA The regular expression that the Tter object compiles. |
string[] |
spli T (charsequence input) Splits the target string according to the regular expression contained in the pattern. |
string[] |
spli T (charsequence input, int limit) Function above, add parameter limit the purpose is to specify the number of segments, such as the Limi set to 2, then the target string will be divided according to the regular expression cut to two paragraphs. |