#!/usr/bin/python3 import re f=open('/tmp/test.txt') for line in f: match=re.findall('^This.*want',line) if match != []: print(match)
结果:
试下编译的正则试试:
复制代码
代码如下:
#!/usr/bin/python3 import re f=open('/tmp/test.txt') re_obj=re.compile('^This.*want') for line in f: match=re_obj.findall(line) if match != []: print(match)