Regular expressions are used for string matching, string lookups, string substitution, and so on. For example, registration of email format verification. The classes related to the processing of regular expressions in Java are mainly java.lang.string,java.util.regex.pattern,java.util.regex.matcher and so on.
Java.util.regex.Pattern is defined in the JDK as:
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 a 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.
Java.util.regex.Macher is defined in the JDK as:
The engine that performs a matching operation on a character sequence by interpreting the Pattern.
Creates a match from a pattern by invoking the Matcher method of the pattern. After you create a match, you can use it to perform three different matching operations:
The 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.
The Find method scans the input sequence to find the next sub-sequence 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.
The typical usage between them is:
Pattern p = pattern.compile ("A*b");
Matcher m = P.matcher ("Aaaaab");
Boolean B = m.matches ();
The java.lang.String matches () method can also verify that the string matches the given regular expression. This method has the same effect as pattern.matches (REGEX,STR).
In the regular expression. +
. A character represented in a regular expression * represents 0 or more. + represents one or more? Represents one or 0
The processing of regular expressions by Java in expression language