title: Regex negative lookbehind on string
body: <p>I cannot seem to be able to find a way to not return a match if a string exists but <strong>not immediately</strong> before another string.</p>
  
  <p>I am able to not return a match if a string exists <strong>immediately</strong> before another string, with the following.</p>
  
  <pre><code>$string = 'Stackoverflow hello world foobar test php';
  
  $regex = "~(Stackoverflow).*?(?&lt;!(test\s))(php)~i";
  
  if(preg_match_all($regex,$string,$match))
      print_r($match);
  </code></pre>
  
  <p>In this example, we want to return a match if we have the word <em>Stackoverflow</em> and <em>php</em> but only if the word <em>test</em>(with a space character) does not exist before the word <em>php</em>.</p>
  
  <p>This doesn't return any result which is good.</p>
  
  <p>Lets now say I want to match <em>php</em> but only if the word <em>foobar</em> doesn't exist somewhere between <em>Stackoverflow</em> and <em>php</em>, I assumed I could do the following.</p>
  
  <pre><code>$string = 'Stackoverflow hello world foobar test php';
  
  $regex = "~(Stackoverflow).*?(?&lt;!(foobar)).*?(php)~i";
  
  if(preg_match_all($regex,$string,$match))
      print_r($match);
  </code></pre>
  
  <p>(I have changed the negative look behind string to (foobar), and added .*? after)</p>
  
  <p>I would also like to say that I cannot always know what words will exist between <em>foobar</em> and <em>php</em>, sometimes there will be none, sometimes 200, but I do have some positioning information (after <em>Stackoverflow</em> and before <em>php</em>).</p>