The Python Regular Expression re findall can return matched substrings in the form of a list.
Re. findall (pattern, string [, flags]):
Search for strings and return all matching substrings in the form of a list. First look at a simpleCode:
Import re
P = Re. Compile (R' \ D + ')
Print P. findall ('one1two2three3four4 ')
### Output ###
# ['1', '2', '3', '4']
A little complex, such:
Info = '<a href = "http://www.baidu.com"> Baidu </a>' Our requirement is to use regular expressions to extract the URL and the anchor text, which can be used
Findall ()
Import Re
Relink = '<A href = "(. *)"> (. *) </a>'
Info = '<A href = "http://www.baidu.com"> Baidu </a>'
Cinfo = Re . Findall ( Relink , Info )
Print Cinfo
Output result: [('HTTP: // www.baidu.com ', 'baidu')] returns a list of tuples formed by matching results. If you need to replace the regular expression, you can check Python RE sub.