搜索字符串与精确长度的文件我有文件包含如何使用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