Python Regular Expressions

Source: Internet
Author: User

1. \d can match a number. ' 00\d ' can match ' 007 '.

2. \w can match one character. ' \w\w\d ' can match ' py3 '.

3.. can match any character. ' Py. ' Can match ' PYc ', ' pc0 ', ' py! ',

4. * denotes any character (including 0).

5. + represents at least one character.

6.? Represents a 0 or 1 character.

7. {n} represents n characters.

8.{n,m} represents a n~m character.

9.[0-9a-za-z\_] can match a number, letter, or underscore.

10.[0-9a-za-z\_]+ can match a string of at least one number, letter, or underscore. such as ' A100 ', ' 0_z '.

11.[a-za-z\_][0-9a-za-z\_]* can match the beginning of a letter or underscore, followed by a string consisting of a number, letter, or underscore, which is the legal variable of Python.

12.[A-ZA-Z\_][0-9A-ZA-Z\_]{0,19} More precisely restricts the length of a variable to 1-20 characters. (up to 19 characters in front of one character + later).

12. | B can match A or b. [P|p]ython can match ' python ' or ' python '.

14. ^ Represents the beginning of the line, and $ represents the end of the line. ^\d indicates that a number must end. \d$ indicates that a number must end. The py can match ' python ', but ^py$ only matches ' py ' and matches the entire line.

\s can match a space (also including a blank character such as tab).

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.