Java knowledge Summary (5) -- Regular Expressions

Source: Internet
Author: User

1. What is straightforward about regular expressions is a powerful tool for processing strings (used for string matching ).

2. for regular expressions, java. Lang. String, java. util. RegEx. pattern, and Java. util. RegEx. matcher are mainly used. The statement is mainly written in the following two ways:

A. stringstring = "sssss ";

String. Matches (". *"); // whether the string matches the regular expression in the form of ". *". If the string matches, true is returned, and vice versa.

B. Pattern pattern = pattern. Compile (". *"); // generates a model class that uses the regular expression ". *" as the model.

Matcher = pattern. matcher ("sssss"); // generates a matching class

Matcher. Matches (); // match

Note: Method A is easier to write than method B, while Method B provides more string matching methods than method.

3. Meanings of common characters in Regular Expressions:

Represents any character * Represents zero or multiple duplicates

+ Indicates one or more repetitions. {} indicates the number of repetitions.

[] Indicates the value range () indicates the meaning of the Group

? Indicates zero or one repeat

Note: More regular expression symbols are described in Java. utit. RegEx. pattern.

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.