title: Regular Expression in sas, not matching a word after a matching word
body: <p>Maybe this is easy, but i could not find a solution.</p>
  <p>I am working in Sas 9.3 with perl regex.
  I am searching for a regular Expression, which matches only some words which are not followed by a specific other word. For example, it should match all text where you have &quot;the car&quot; and in all other text after this there should be no &quot;not&quot;. (Case can be ignored, because i upcase everything in my code)</p>
  <p>Should match</p>
  <blockquote>
  <p>This is not the car i want</p>
  <p>The car is green</p>
  </blockquote>
  <p>should not match</p>
  <blockquote>
  <p>The car is not green</p>
  <p>This is the car i want, but its not available</p>
  </blockquote>
  <p>One solution would be to split it in two matches:</p>
  <p><code>prxmatch(&quot;/The car/&quot;,mytext) &gt; 0 and prxmatch(&quot;/The car.+not/&quot;,mytext)=0</code></p>
  <p>But i have to use the logic a lot of times, also in more complex cases, so i dont want to always use 2 prxmatch and instead combine the logic in one prxmatch.</p>
  <p>I read a lot about look aheads and tried some examples, but they did not work correct, e.g.:</p>
  <pre><code>&quot;/The Car.+[^(not)]/&quot;
  </code></pre>
  <p>or</p>
  <pre><code>&quot;/The Car.+(?!not)/&quot;
  </code></pre>
  <p>or</p>
  <pre><code>&quot;/^(?!.*not.*).*?The car.*$/&quot;
  </code></pre>
  <p>1st and second return all 4 texts as results, third none result at all.</p>
  <p>So can somebody provide me a solution for this, a simple not Operator for a word or a correct look ahead/behind Approach?</p>