标签:贪婪模式 class 数字 表达式 match ber splay 操作 python基础
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‘ >>>
标签:贪婪模式 class 数字 表达式 match ber splay 操作 python基础
原文地址:https://www.cnblogs.com/pythonClub/p/10354011.html