re正则匹配中括号贪婪与非贪婪

贪婪

str = [abc[def]gh]
pat = r"([.*])"
result = re.findall(pat, str,re.M)
pringt(result)

>>> [abc[def]gh]

非贪婪

str = [abc[def]gh]
pat = r"([.*?])"
result = re.findall(pat, str,re.M)
pringt(result)

>>> [abc[def]
原文地址:https://www.cnblogs.com/ouzai/p/13816026.html