Python Basics-Regular 1

Source: Internet
Author: User

What is a regular expression?

A regular expression is a small, highly specialized, language that is used primarily for string processing

Regular expressions are a common language, implemented in Python via the RE module, and the import re

Tools: on-line regular expression testing

http://tool.oschina.net/regex/

Http://www.jb51.net/shouce/jquery1.82/regexp.html

Character match-Normal character

Most characters match themselves exactly. The expression shit matches the string "shit" exactly

Character match-Meta character

^ Match beginning of Line

$ Match Line End

* Match the previous character by more than or equal to 0 times

? Matches the previous character 0 or 1 times to indicate whether a

+ Match the previous character by more than or equal to 1 times

. Match single character

[] Specify a character set [ABC]; [A-z]; [1-9];  [A-za-z0-9] (or a relationship, such as [ABC] indicates the presence of a or B or c other similar)

In addition, you can match characters that are not in the interval range [^5], where you must use []

\ transfer metacharacters to normal characters \ \, \^, \[

Eg: want to match the number in the string (ONE1TWO2THREE3FOUR4)

Regular:/d

{} Number of repetitions

What does eg:a{4} mean?

Match AAAA

| Represents or, X|y represents a match for x or Y

() grouping

eg

Regular: C|d, match string "ABCD", result?

Cd

Regular: (AB), match string "ABC ADC ABB", result?

Explanation: AB whole goes to match string

AB AB

Summarize:

  

Practice:

data [' AD123453 ', ' AC345466 ', ' AR695235 '], matching 2 uppercase letters and 6 digits

\W{2}\D{6} \w+\d+ [A-z]{2}[0-9]{6}

Match the domestic mobile phone number

Features: All numbers

Opening 1X

Length 11

^ (13|15|18) [0-9]{9}

Python Basics-Regular 1

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.