Python regular expression (1)

Source: Internet
Author: User

A regular expression (regular exprssion) is a text match pattern described by a formal syntax. The mode is interpreted as a group of commands, and then the group of commands is executed. Use a string as the input to generate a matching subset or a modified version of the source string.

Expressions can include literal text matching, repetition, mode combination, and other complex rules at the branch level.

  • Search for patterns in text

The most common usage of re is to search for the mode in text. The search () function uses the pattern and text of the sample code as the input. If this pattern is found, a Match object is returned. If None is found, None is returned.


Group () shows the matched string

Start () end () indicates the position where the text matching the pattern appears in the string.

Found 5 to 9 ()

You can also use the span () function to return the position of the matched string (match. span ())

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