In my opinion, the logic of the original is wrong. I guess that the intention was to print only the lines that do not start or with *NODE or with *ELEMENT OUTPUT (case insensitive). However, the condition holds for any line. If it starts with *NODE then it does not start with *ELEMENT OUTPUT and vice versa. This way, the condition is always evaluated to True.
The conclusion, there must be and instead of or even in the original.
Also, you must use raw strings (like r'your pattern' in Python or you have to double the backslashes. I believe, you do not want to double backslashes in regular expressions.
You can try the following snippet:
import re
simulated_file_content = [
'line 1\n',
'*NODE line 2\n',
'line 3\n',
'*eLeMent Output line 4\n',
'line 5\n',
]
rex = re.compile(r'^\*(NODE)|(ELEMENT OUTPUT)', re.IGNORECASE)
for line in simulated_file_content:
line = line.rstrip()
if not rex.search(line):
print line
It displays:
c:\tmp\___python\FaisalSashmi\so12153650>python a.py
line 1
line 3
line 5