Getting Started with Python re library (regular expression)

Source: Internet
Author: User

Regular Expressions (English name: regular expression,regex,re) are expressions that are used to succinctly Express a set of character strings. The most important applications are in string matching.

syntax for regular expressions -common operators:

 
Operator Description Instance
. Represents any single character
[ ] Character set, giving a range of values to a single character [ABC] means a, B, c,[a-z] represents a to Z single character
[^ ] Non-character sets, exclusion ranges for individual characters [^ABC] Represents a single character that is not a or B or C
* Previous character 0 or unlimited expansion abc* means AB, ABC, ABCC, ABCCC, etc.
+ Previous character 1 or unlimited expansion abc+ means ABC, ABCC, ABCCC, etc.
? The previous character 0 or 1 times extended Abc? Represents AB, ABC,
| Left and right expression any one Abc|def means ABC, DEF
{m} Extend one character m times Ab{2}c says ABBC
{M,n} Extend one character M to n times (with N) Ab{1,2}c means ABC, ABBC
^ Match string start ^ABC represents ABC and at the beginning of a string
$ Match string End abc$ represents ABC and at the end of a string
( ) Grouping tags, which can only be used internally | Operator (ABC) means ABC, (ABC|DEF) means ABC, DEF
\d number, equivalent to [0-9]
\w Word character, equivalent to [a-za-z0-9]

Regular expression that matches the IP address:

Regular expressions in the form of IP address strings (IP address divided into 4 segments, 0-255 per segment)

Exact wording 0-99:[1-9]?\d

100-199:1\d{2}

200-249:2[0-4]\d

250-255:25[0-5]

([1-9]?\d| 1\D{2}| 2[0-4]\d| 25[0-5]).) {3} ([1-9]?\d| 1\D{2}| 2[0-4]\d| 25[0-5])

Getting Started with Python re library (regular expression)

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.