Illustration of the guide to using python regular expressions

Source: Internet
Author: User
The last time many of my friends used regular expressions to write text blocking, they didn't actually mean I didn't want to use it (I didn't use many regular expressions. I know what crawlers I used to do before, I directly use the webpage tag of BeautifulSoup to find the content, because it is easy to understand and convenient.) instead, it is very difficult to use regular expressions. (you should know that you have read regular expressions, there are many rules for the method corresponding to the symbols in it.) for friends who have been familiar with programming, the last time many friends wrote text blocking, they said they should use regular expressions, actually, it's not that I don't want to use it (I don't use a lot of regular expressions. I know all of my previous crawlers. I use the webpage tag of BeautifulSoup to find the content, because it is easy to understand and convenient ,), instead, it is difficult to use regular expressions and be proficient (users who have read the regular expression table should know that there are many methods and rules corresponding to the symbols in the regular expression table, which are flexible ), for friends who are not familiar with programming, it is likely to waste a lot of time in the programming process. today I will introduce regular expressions frequently, and if it is not very special, it will be overwritten.

1. Introduction to regular expressions

First, you need to import the regular expression method import re regular expression, which is a powerful tool for processing strings. it has its own processing mechanism, which may be less efficient than the built-in str method, but its functions are very flexible and powerful. Its running process is to first set a matching rule ("The content you want + regular syntax rules"), put the string to be matched, you can use the regular expression internal mechanism to retrieve the information you want.

2. several common findall postures

Basic structure: nojoke = re. findall (r 'matched rule', 'desired string') nojoke is the final result returned by regular expressions, re-regular findall: find all the r Identifiers. the regular statements are followed by the regular expressions (so that you can check them when there are many codes). let's take a look at several examples to learn more.

-->

The above is the detailed illustration of the guide using python regular expressions. For more information, see other related articles in the first PHP community!

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.