Common Regular Expressions

Source: Internet
Author: User

Blog for the first time the essay was dedicated to the regular expression.

one: In Java introduced after JDK1.4, all the regular supported classes are defined in the Java.util.regex package . two: Regular tag: All the tags that can be used are in Java.unti.regex. The pattern class is defined inside. 1, "single" describes a character
    • X: Represents a character consisting of x;
    • \ \: Matches the escape character "\";
    • \ t: Description tab "\ T";
    • \ n: Matches line break "\ n";
2, "single" describes a range
    • [ABC]: The expression may be any of the letters A, B, C;
    • [^ABC]: Indicates that it is not a letter A, B, c any one;
    • [0-9]: Any number representing 0 to 9;
    • [A-za-z]: denotes any single letter, not case-sensitive;
    • [A-Z]: denotes any of the lowercase letters;
    • [A-Z]: represents any of the uppercase letters.
3, "single" Simplified expression
    • “.” : Represents any one character, while \ \. means "." )
    • \d: Equivalent to [0-9], indicating any one digit;
    • \d: Equivalent to [^0-9], representing any one non-digit;
    • \s: denotes any one whitespace character, possibly a space, \ t, \ n;
    • \s: Denotes any one non-whitespace character;
    • \w: Equivalent to [a-za-z_0-9], which is composed of letters, numbers and underscores;
    • \w: Equivalent to [^a-za-z_0-9].
4, boundary matching (not in Java, JS must be used)
    • ^: expression of the beginning of the regular;
    • $: Indicates the end of the regular.
5, the quantity expression (can be used when repeated appearance)
    • The regular? : Indicates that this regular match can occur 0 or 1 times;
    • Regular +: Indicates that this regular match appears 1 or more times;
    • Regular *: Indicates that this regular match appears 0 times, 1 times or more;
    • Regular {n}: Indicates that this regular match occurs exactly n times;
    • Regular {N,}: Indicates that this regular match appears n or n times;
    • Regular {N,m}: Indicates the occurrence of n~m times.
6. Logical Operation
    • Regular a regular B: regular A matches the regular B immediately after the match is finished;
    • Regular a| regular B: Regular A or regular B has a set of satisfied;
    • (regular): multiple regular as a set of processes, you can set the number of occurrences of this set alone.
specific usage of regular expressions reference to: String class support for regular expressions

Common Regular Expressions

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.