Python Basics - Regular 2 (0503)

1. Regular

1. A relatively easy-to-use regular matching website https://regex101.com/

2, commonly used regular

     What starts/ends with: ^ starts $ ends

     The number of times to match the previous character, 0 to infinite   *

     The number of times to match the previous character, 1 to infinite   +

     Match the previous character m times {m} For example: ab{2}c is abbc

3. Greedy matching .* Non-greedy matching .*?

4. Regular matching practice

 

 

 

 

2. Regular module re-related functions

1、re.match  

     Attempt to match a pattern from the beginning of the string, if the match is not successful at the beginning, match() returns none

     Function syntax re.match(pattern, string)    

     where pattern is the regular expression to match, string is what to match,

     Example:

     result:

2. re.search scans the entire string and returns the first successful match    

     Example:

     result:

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325286532&siteId=291194637