python贪婪和非贪婪
>>> s="This is a number 234-235-22-423"
>>> r=re.match(".+(\d+-\d+-\d+-\d+)",s)
>>> r.group(1)
‘4-235-22-423‘
>>> r=re.match(".+?(\d+-\d+-\d+-\d+)",s)
>>> r.group(1)
‘234-235-22-423‘
>>>
>>> re.match(r"aa(\d+)","aa2343ddd").group(1) ‘2343‘ >>> re.match(r"aa(\d+?)","aa2343ddd").group(1) ‘2‘ >>> re.match(r"aa(\d+)ddd","aa2343ddd").group(1) ‘2343‘ >>> re.match(r"aa(\d+?)ddd","aa2343ddd").group(1) ‘2343‘ >>>
原文:https://www.cnblogs.com/pythonClub/p/10354011.html