I need to search multiple words in each line and if all the words are matching in a line then print that line.
file.txt
This is starting string.
This is starting but different string.
This is starting but the same string.
This is a differnet string.
This is a old string.
i have done in below manner.
import re
with open("file.txt", "r") as in_file:
for line in in_file:
if (re.search('different',line)) and (re.search('string',line)):
print line
But i need something like:
if (re.search('different' and 'string',line))::
print line
I know we have or as we use
if (re.search('different'|'string',line))::
print line
Can anybody help me to use 'and' in similar manner.