标签:findall 总结 ble bsp mode com 语法 uil var
非贪婪模式
非贪婪匹配:尽可能少的匹配
{n,}?
{,n}?
{n,m}?
*?
+?
??
应用场景: 正则一定会有首尾标识,中间匹配的结果会有非贪婪匹配的语法
s = ‘<a>abc</a><a></a>‘
匹配标签
print(re.findall(r‘<.*>‘, s)) # [‘<a>abc</a><a></a>‘]
print(re.findall(r‘<.*?>‘, s)) # [‘<a>‘, ‘</a>‘, ‘<a>‘, ‘</a>‘]
匹配标签的内容
print(re.findall(r‘<a>(.*)</a>‘, s)) # [‘abc</a><a>‘]
print(re.findall(r‘<a>(.*?)</a>‘, s)) # [‘abc‘, ‘‘]
标签:findall 总结 ble bsp mode com 语法 uil var
原文地址:https://www.cnblogs.com/xzcvblogs/p/10847188.html