Regular expressions and the use of the Python re library

Source: Internet
Author: User
The content of this article is regular expression and the use of Python re library, now share to everyone, the need for friends can refer to the content of this article


Regular expressions and the use of the Python re library


Note: Images and related codes are sourced from MOOC

Regular expressions

Common operators for regular expressions

Regular expression Syntax instances

Regular expressions in the form of IP address strings

Use of the Python re library

The representation type of a regular expression

When the regular expression contains an escape character, use the raw string

Re Library main function function

Example

Import rematch = Re.match (R ' [1-9]\d{5} ', ' BIT 100081 ') print (Match.group (0)) # The MATCH function matches the regular expression from the beginning of a string, so the variable match should be equal to # None, so the above code will throw an exception, the correct wording is to first judge the match

Another equivalent usage of the RE library

Pat is a regular expression object compiled from a regular expression string and can directly use the functions of the 6 >re libraries above.

Match object for RE library

The properties of the match object

Greedy match and minimum match for RE Library

The RE library uses greedy matching by default, which is the output that matches the longest string

Related Article

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.