Python Regular Expressions

Source: Internet
Author: User

1. If the special characters are literal in use, they need to precede them with a backslash (\) and special characters include \. ^ $ ? + * { } ( ) [ ] |

2. If you want to match any one of the character sets, you can use the character class to implement-one or more characters enclosed in square brackets. The character class is an expression, such as a regex r[ea]d that matches Red and radar (the underlined portion of the match).

3. Within a character class, except for \, special characters no longer have their special meaning, exceptions are

    • If the ^ symbol is the first character of a character class, it is using its special meaning (negation), but in other cases, it is still just a literal ^ symbol
    • If-represents a range of characters, if it is the first character of a character class, it represents a literal hyphen

4. Shorthand for character classes:

    • . (decimal point): You can match any character except the line break, or with re. Dotall any character that is marked, or character that matches the literal meaning inside a character class
    • \d: Matches a Unicode number, or with re. ASCII tagged [0-9]
    • \d: Matches a Unicode non-numeric, or with re. ASCII tagged [^0-9]
    • \s: Matches a Unicode blank, or with re. ASCII tagged [\t\n\r\f\v]
    • \s: Matches a Unicode non-whitespace, or with re. ASCII tagged [^ \t\n\r\f\v]
    • \w: Matches a Unicode word character, or with re. ASCII tagged [a-za-z0-9_]
    • \w: Matches a Unicode non-word character, or with re. ASCII tagged [^a-za-z0-9_]

Python 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.