import re
line = “Cats are smarter than dogs”
matchObj = re.match(r’(.) are (.?) than (.*) ', 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))
print("matchObj.group(3) : ", matchObj.group(3))
在正则表达式中要严格注意空格的存在,否则就会得到匹配不成功的结果。