re.match(r"aa(\d+?)","aa2343ddd").group()
Out[45]: 'aa2'
re.match(r"aa(\d+?)d","aa2343ddd").group()
Out[46]: 'aa2343d'
re.match(r"aa(\d+?)d??","aa2343ddd").group()
Out[43]: 'aa2'
re.match(r"aa(\d+?)d+","aa2343ddd").group()
Out[44]: 'aa2343ddd'
re.match(r"aa(\d+?)d+?","aa2343ddd").group()
Out[42]: 'aa2343d'
re.match(r"aa\d+?d+?","aa2343ddd").group()
Out[65]: 'aa2343d'
总结:python正则表达式的非贪婪模式会尽量少得去匹配字符串,比如说r”aa(\d+?)d+”中,组1按道理只能匹配一个数字,但在这里却匹配了多个数字,这是因为就组1它是尽量少的去匹配字符,但对于整个patt,也就是组0,却是尽可能多地去匹配字符串。即每个包含?的模式分组或模式部分会尽可能少得去匹配字符,但是就整个模式而言还是会尽可能贪婪地取匹配字符串。