Home >Backend Development >Python Tutorial >Python regular expression summary
search(pattern, string, flags=0): Find a match in a string
finddall(pattern, string, flags=0): Find a match and return a list of all matching parts
sub(pattern, repl, string, count=0, flags=0): Replace the part of the string that matches the regular expression with other values
split(pattern, string, maxsplit=0, flags=0): Split the string according to the match, Returns a list of split strings
import urllibimport re req = urllib.urlopen('http://www.imooc.com/course/list') buf = req.read() listurl = re.findall(r'http:.+\.jpg', buf)print listurl i = 0for url in listurl: f = open(str(i) + '.jpg', 'w') req = urllib.urlopen(url) buf = req.read() f.write(buf) i += 1
The above is the detailed content of Python regular expression summary. For more information, please follow other related articles on the PHP Chinese website!