#!/usr/bin/pythonimport reline = "Cats are smarter than dogs"matchObj = re.match( r'(.*) are (.*?) .*', line, re.M|re.I)if matchObj:print "matchObj.group() : ", matchObj.group()print "matchObj.group(1) : ", matchObj.group(1)print "matchObj.group(2) : ", matchObj.group(2)else:print "No match!!"以上实例执行结果如下:matchObj.group() : Cats are smarter than dogsmatchObj.group(1) : CatsmatchObj.group(2) : smarter请问, r'(.*) are (.*?) .*',这个是匹配什么东西,是如何匹配的?好像很复杂的样子,另外matchObj.group(1)可以有输出,填3的时候就出错了?
添加回答
举报
0/150
提交
取消