Summary of Java regular expression knowledge points

Source: Internet
Author: User
Tags modifier

A regular expression is a string of characters that contain special meanings, which are called metacharacters in regular expressions. For example, "\\dhello" in the \\d is a special meaning of the meta-character, representing any of the 0~9. Both the string "9hello" and "1hello" are one of the strings that match the regular expression "\\dhello".

(1) The string object calls the public Boolean matches (string regex) method to determine whether the current string object matches the regular expression specified by the parameter regex;

(2) Common metacharacters and its significance are as follows:

(3) In a regular expression, you can enclose several characters in square brackets to represent metacharacters, which represent any one character in square brackets. For example regex= "[159]abc", then "1ABC", "5ABC", "9ABC" are strings that match the regular expression regex.

[ABC]: Represents any of a, B, C;

[^ABC]: represents any one character except A, B, C and foreign;

[A-za-z]: represents any one of the English letters;

[A-d]: represents any one of the a-d;

[A-d[m-p]]: Represents a to D, or M to p any character (and);

[A-z&&[def]]: represents any of the D, E, F (intersection);

[A-F&&[^BC]: Represents a, D, E, f (difference)

(4) The qualifier modifier can be used in regular expressions. For example, using the qualifier modifier:?, if x represents a metacharacters or ordinary character in a regular expression, then X? means x appears 0 or 1 times, for example:

regex= "a[2468", "A", "A2", "A4", "A6", "A8" are all strings that match the regular expression regex.

Common qualifier modifiers are used as follows:

(5) The regular expression use case is as follows:

Summary of Java regular expression knowledge points

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.