Python-- regular match_compile_search_findall usage
Regular expressions are powerful, but it takes you some time to master them.
The following explains the common methods of match, compile, search and findall
Match
Match starts with the first character of the string. If it does not match to return None, it returns an object.
Did not match to return None
The starting character matches to h, and an object is returned, and the h value needs to be obtained through group.
Search
Search is somewhat similar to match, except that searching the entire string and then the first match to the specified character returns a value, and if it does not match, it returns None. To get a worthwhile method, you also need to use group ()
Returns None if it does not match the character
Match back from the string, and an object is returned as soon as the match is reached. The matching value needs to be obtained through group.
Findall
Findall matches all the values in the string related to the specified value and returns as a list. If it does not match, an empty list is returned.
Did not match to return an empty list.
Matches all values of the specified character and returns values as a list.
Compile
Re.compile converts regular expressions into pattern objects so that they can match more efficiently. After using compile to convert once, you don't have to convert each time you use the pattern in the future
In fact, this is the same result as executing re.findall ('img',a), except that after using compile, you don't need to convert the schema object again when you execute the findall method.