import re
import fileinput
for line in fileinput.input('C:\\temp\\Scripts\\remove.txt', inplace=True):
    if not re.search('\\byahoo\\b', line):
        pass
Using Python to Remove All Lines Matching Regex