Python 正则表达式search函数 Python 正则表达式 Python 正则表达式 匹配(match) vs 搜索(search) Python 正则表达式search函数 #!/usr/bin/python import re line = "Cats are smarter than dogs"; searchObj = re.search( r'(.*) are (.*?) .*', line, re.M|re.I) if searchObj: print "searchObj.group() : ", searchObj.group() print "searchObj.group(1) : ", searchObj.group(1) print "searchObj.group(2) : ", searchObj.group(2) else: print "Nothing found!!" Python 正则表达式 Python 正则表达式 匹配(match) vs 搜索(search)