我的問題是類似this one,但我想搜索多個chars
的發生,例如g
,d
和e
,然後打印線所有指定的字符都存在。使用Python來搜索文本文件中的特定字符的發生
我曾嘗試以下,但它沒有工作:
searchfile = open("myFile.txt", "r")
for line in searchfile:
if ('g' and 'd') in line: print line,
searchfile.close()
我得到了它的「G」或「d」或兩者在其中,我要的只是兩個OCCURENCES線,至少不是其中之一,因爲運行上述代碼的結果。
你有嘗試過什麼嗎?這不難實現,不需要正則表達式。 – Blender 2013-03-23 22:00:20