import re s = """ <div class='jay'><span id='1'>周杰伦</span></div> <div class='augus'><span id='2'>马宁</span></div> <div class='tom'><span id='3'>马铭皓</span></div> <div class='jarry'><span id='4'>杰瑞</span></div> <div class='lucy'><span id='5'>路西</span></div> """ obj = re.compile(r"<div class='.*?'><span id='.*?'>(?P<name>.*?)</span></div>",re.S) result = obj.finditer(s) for it in result: # print(it.group()) print(it.group("name")) #例子中,在原本的".*?"的位置变更为"(?P<name>.*?)" ,这样在下面的group中用name的变量名就可以提取到当前的
标签:语句,group,re,Python,正则表达式,result,print,obj From: https://www.cnblogs.com/minhoo/p/18060067