 <p>You can use</p> <pre><code>(?im)^.*\bthe car\b(?!.*\bnot\b).* </code></pre> <p>The <a href="https://regex101.com/r/pT0mP7/2" rel="nofollow">regex demo is available here</a></p> <p>Pattern breakdown:</p> <ul> <li><code>(?im)</code>- enable case-insensitive and multiline matching modes</li> <li><code>^</code> - start of a line (since <code>(?m)</code> is used)</li> <li><code>.*</code> - match 0+ any characters but a newline</li> <li><code>\bthe car\b</code> - 2 whole words "the car" (a sequence of 2 words)</li> <li><code>(?!.*\bnot\b)</code> - a negative lookahead that fails the match if there is a whole word "not" somewhere to the right of <code>the car</code></li> <li><code>.*</code> - the rest of the line up to the newline or end of string</li> </ul>