The regular expression of Python

Source: Internet
Author: User

I. INTRODUCTION

A regular expression (or RE) is a small, highly specialized programming language (in Python) that is embedded in Python and implemented through the RE module and then compiled into a series of bytecode that is then executed by a matching engine written in C

Two. Common operation

1. Character Matching

      • Metacharacters
. Substituting any character except a newline character, which can match only one of the characters
^ Match beginning
$ Match end of Line
* Repeat match 0~ multiple times, greedy match
+ Repeat match 1~ multiple times, at least one match
? Match 0 or one time, optional, up to only one
{} Determine the number of matches, or range
[] Commonly used to develop a character set, such as [AB] matches a or b; other metacharacters do not work in [] except for "-" "^"
| Or
() Grouping The first group number is 1
\ Translated
      • Special characters

\d Match any decimal number; it is equivalent to class [0-9].
\d Matches any non-numeric character; it is equivalent to a class [^0-9]
\s Match any whitespace character; it is equivalent to class [\t\n\r\f\v]
\s Matches any non-whitespace character; it is equivalent to a class [^ \t\n\r\f\v]
\w Match any alphanumeric character; it is equivalent to a class [a-za-z0-9_]
\w Matches any non-alphanumeric character; it is equivalent to a class [^a-za-z0-9_]
\b Match a word boundary, that is, the position between the word and the space

The regular expression of Python

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.