Regular Expression Learning notes (ii)

Source: Internet
Author: User

Corrected an error yesterday I used match this only matches the first one with matches to match all the regular expression characters

4. The inverse of the character class
    • [^a] means matching any characters that are not "a"
    • [^a-za-z0-9] means matching any character that is not a letter or a number
    • [\^ABC] matches a character that is "^" or a or B or C
    • [^\^] means matching any characters that are not "^"

5. Escape character class

How to shorten the length of regular expression effectively?

    • \d = [0-9] Functions the same, all matching any one number. (Regular expression \\d should be used to match \d)
    • \d = [^0-9] has the same function, which means matching a non-numeric character.
    • \w = [0-9a-za-z] has the same function, which means matching a number or alphabetic character
    • \w = [^0-9a-za-z] has the same function, which means matching a non-numeric character that is not a letter at the same time.
    • \s means matching a null character (space, tab, carriage return or line break)
    • \s indicates that a non-null character is matched.
6. Repeat

After a character or character set, you can use the {} brace to represent a duplicate

    • The regular Expression A{1} is the same as a meaning that all matches the letter A
    • A{3} indicates a match string "AAA"
    • A{0} indicates a match to an empty string. Judging from the regular expression itself, it is meaningless. If you perform such a regular expression on any text, you can navigate to where the search starts, even if the text is empty.
    • A\{2\} indicates a match string "a{2}"
    • In character classes, curly braces have no special meaning. [{}] means matching a left curly brace, or a right curly brace

Example

    • z.......z = z.{7}z
    • \d\d\d\d-\d\d-\d\d = \d{4}-\d{2}-\d{2}
    • [aeiou][aeiou][aeiou][aeiou][aeiou][aeiou] = [aeiou]{6}

Note: Repeated characters are not memory, such as [abc]{2} means match "A or B or C", and then match "A or B or C", and match "AA or AB or AC or BA or BB or BC or CA or CB or CC". [ABC] {2} does not indicate a match for "AA or BB or cc"

Regular Expression Learning notes (ii)

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.