Regex Search in Python: Exclude port 22 lines with ' line 22 '
Question: My current regex search in python looks for lines with `' 22 '`, but I would
like to exclude lines that have `' line 22 '`. How could I express this in
`Regex`? Would I be `'.*(^line) 22 .*$'`

    
    
    import re
    
    sshRegexString='.* 22 .*$'
    sshRegexExpression=re.compile(sshRegexString)
    


Answer: You current requirement to find a line that _contains_ ` 22 ` but does not
contain `line 22 ` can be implemented without the help of a regex.

Just check if these texts are `in` or are `not in` the string inside list
comprehension. Here is a [Python demo](http://ideone.com/o2jFU7) (I assume you
have lines in a list, but it can be adjusted to handling lines read from file
one by one):

    
    
    lines = ['Some text 1 line 22 here', 'Some text 2 Text2 22 here', 'Some text 3 Text3 22 here']
    good = [s for s in lines if ' 22 ' in s and 'line 22 ' not in s]
    print(good) # the first lines[0] is not printed!
    

