|
#!/usr/bin/python
# -*- coding: UTF-8 -*-
import re
line = "Cats are smarter than dogs"
matchObj = re.match( r'(.*) are (.*?) .*', line, re.M|re.I)#按照rematch正则表达式的格式re.match(匹配的正则表达式, 字符串,标志位 ),该行的定义怎么理解?
if matchObj:
print "matchObj.group() : ", matchObj.group()
print "matchObj.group(1) : ", matchObj.group(1)#这条语句执行后,输出为:matchObj.group(1) : Cats
print "matchObj.group(2) : ", matchObj.group(2)#这条语句执行后,输出为:matchObj.group(2) : smarter,如果按照group()组从1开始,这里为2的时候为什么输出不是are?
else:
print "No match!!"
|
|