搜索字符串與精確長度的文件我有文件包含如何使用python
google
google talk browser
google talks
google talk
如何使用Python搜索「談判」的文件,準確地搜索,無需額外的字符串和使用python
打印線搜索字符串與精確長度的文件我有文件包含如何使用python
google
google talk browser
google talks
google talk
如何使用Python搜索「談判」的文件,準確地搜索,無需額外的字符串和使用python
打印線只需使用比較操作:
with open('file.txt', 'r') as handle:
for index, line in enumerate(handle, 1):
if line.strip() == 'google talk':
print 'Match found on line', index
import re
txt = open("youfile.txt").read()
if re.search(r'[^\s]?google talk[\s$]?',txt):
//code for string present
else:
//code for string not-present
我想只搜索「交談」,並打印行和不打印「談話瀏覽器」和「會談」我該怎麼做。 – user1699309
我很困惑。你不是在尋找一條等於'talk'的線嗎? – Blender