我正在尝试使用正则表达式在文本文档中的一行上查找特定单词。我尝试使用下面的代码,但它不能正常工作。
import re
f1 = open('text.txt', 'r')
for line in f1:
m = re.search('(.*)(?<=Dog)Food(.*)', line)
m.group(0)
print "Found it."
f1.close()
错误:
Traceback (most recent call last):
File "C:\Program Files (x86)\Microsoft Visual Studio 11.0
ns\Microsoft\Python Tools for Visual Studio\2.0\visualstudi
0, in exec_file
exec(code_obj, global_variables)
File "C:\Users\wsdev2\Documents\Visual Studio 2012\Projec
TML Head Script\HTML_Head_Script.py", line 6, in <module>
m.group(0)
AttributeError: 'NoneType' object has no attribute 'group'