贪婪模式:在表达式匹配成功的前提下,总是尽可能多的匹配字符飞天蓝模式:在表达式匹配成功的前提下,总是尽量少的匹配字符
1 # !/usr/bin/env python
2 # -*- coding:utf-8 -*-
3 import re
4
5 def test():
6 string =
"abc123456789sdsddskcas"
7 print "a(.*)c贪婪模式匹配结果:"
8 print re.findall(r
"a(.*)c",string, re.S)
9 print "a(.*?)c非贪婪模式匹配结果:"
10 print re.findall(r
"a(.*?)c",string, re.S)
11 if __name__==
'__main__':
12 test()
运行结果:
转载于:https://www.cnblogs.com/nixiaocang/p/6592374.html