The processing of regular expressions by Java in expression language

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.