Python 10_regular expression (1)

Source: Internet
Author: User

Recently, the status has not been very good. As for the reason, what should I do? Well, in short, the Tangle is covered by the tangle, And the mind is totally different, I hope I can adjust it back by using Python learning and blog writing. Sometimes I may think back. If it is my own problem, I often told others before that I should never doubt myself, it is clear that once I have become untrustworthy, the world will be crazy. When I ask myself again and again, I may doubt myself, I tried to convince others over and over again. I couldn't think of how sad it is to convince myself ~

I. Basics of Regular Expressions 1. Basic Concepts

Regular Expressions are a concept of computer science. Regular Expressions use a single string to describe and match a series of strings that conform to a certain syntax rule. In many text editors, regular expressions are usually used to retrieve and replace texts that match a certain pattern.

A regular expression is a logical formula for string operations. It uses predefined characters and combinations of these specific characters to form a "rule string ", use this "rule string" to perform a logical filter on the string.

2. Common Structures

The following figure is stolen, the source of http://www.cnblogs.com/huxi/archive/2010/07/04/1771073.html

Examples/HU8re1u9hOb25lLMO/upznyxw.albuz/examples + wP3I58/Co7o8L3A + PHA + pgltzybzcm9 "http://www.2cto.com/uploadfile/Collfiles/20140516/20140516093800169.jpg" alt = "\"/>

It was originally compiled directly on subline Text2, but it didn't respond after compilation. After a slight check, I found that I had SB and there was a Chinese path, so I had to use the Python editor.

2. Compile the expression

The re module contains many module-level functions, which are used to process regular expressions of text strings. However, for expressions frequently used by programs, compiling these expressions is very efficient. compile () in the re Module () the function shows its value as follows:


3. Multiple matching

In the previous example, we used search () to find a single instance of text. But what if I want to find all strings that meet the pattern in a text that do not overlap? Findall () is used here, for example:


Finditer () returns an iterator pointing to the matching instance.


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.