Python Regular Expressions

Source: Internet
Author: User

Special characters in Python regular expressions:

^ indicates that the matching character must be in the front

$ indicates that the matching character must be on the last side

* Match * preceding characters 0 or n times

+ match + previous characters 1 or n times

?  The? The preceding character 0 or 1 times

. (decimal point) matches all characters except line break

(x) match x and record matching values

x|y match x or Y

{n} here n is a positive integer. Match the preceding n characters

{n,} here n is a positive integer. Matches at least n preceding characters

{n,m} here N and M are all positive integers. Matches at least N, up to M preceding characters

[XYZ] character list, which matches any one of the characters in the table, can be connected by character-indicating a range of characters, such as [A-z] for all lowercase letters

[b] matches a space

b matches the dividing line of a word, such as a space

B matches the non-dividing line of a word


re module matching rules (the third parameter of the Re.match function):

Re. IGNORECASE ignoring the case in the text

Re. Locale handles character set localization

Re. MULTILINE support for multi-line matching

Re. Dotall matches some special tags, such as using. Match \ n characters

Re. VERBOSE ignores whitespace or newline characters in regular expressions

Re. Unicode uses Unicode encoding

Here is an example of a matching mailbox

def isemail (email):     BOOL (Re.match (R"^ ([a-za-z]+) ([0-9]*) @ ([a-z0-9a-z]+\.) +[a-za-z]{2,}$", email, re. IGNORECASE))    if  isMatch:        "email is correct. "    Else :         " email is wrong. "    return IsMatch

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.