title: Match text if it doesn't contain a certain substring
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/12447818/regex-preg-no-match-if-found">Regex / Preg: No match, if found</a>  </p>
  </blockquote>
  
  
  
  <p>I want to use <code>preg_replace</code> to replace some string if something in the string is NOT there. That is, if the substring is there, the string won't be matched.</p>
  
  <p>For example, if the string contains <code>.png</code>, it won't find/match it.</p>
  
  <pre><code>example.com/image.png
  </code></pre>
  
  <p>Here, it will not find it because the string contains the line/substring <code>.png</code>.</p>
  
  <pre><code>example.com/image
  </code></pre>
  
  <p>Here, it will find it, because the string does <strong>not</strong> contain the line/substring <code>.png</code> anywhere.</p>
  
  <hr>
  
  <p>For those who still does not get me.</p>
  
  <pre><code>$result = preg_replace("#http://(.*\S)[Something here that will not match the link if it finds the .png at last]#","&lt;a href='\\1'&gt;\\1&lt;/a&gt;","Here is a link that should work http://example.com/; Here is a link that should NOT work http://example.com/image.png")
  </code></pre>