Q:

Count occurrences of string in lines with boolean AND

I'm very new to Python but have a need to read the lines of a text file and count the occurrences of multiple strings using boolean AND.  For instance, if a particular line contains 'blue' AND 'green' I need to count the number of lines this is true for.  This is what I have so far.
import re
file = open("text.txt")
lines = file.readlines()
print(lines.count('blue')
file.close()

Your assistance is appreciated.

A:

Using Regex:
import re
count = 0
with open(filename, "r") as infile:
    for line in infile:
        if re.search(r"\bblue\b", line, flags=re.IGNORECASE) and re.search(r"\bgreen\b", line, flags=re.IGNORECASE):
            count += 1
print(count)

\b Regex boundary 

