匹配的正則表達式我寫了下面的代碼在Python匹配內部文件的字符串:
的Python:在文件
#!/usr/bin/python
import re
f = open('file','r')
for line in f:
mat = re.search(r'This',line)
mat.group(0)
f.close()
我用下面的文件作爲輸入:
This is the first line
That was the first line
但是,當我嘗試搜索表達式This
它導致None
輸出。 爲什麼不是字符串不匹配?
@stribizhev你不需要那樣。另外你不打印'.group(0)' – muddyfish