title: PHP preg_replace regex exclude html <a> tag
body: <p>The goal would be:
  I have some titles. I would like to turn the titles in a text to link. BUT when it is a link, I DON'T want to change. I am looking for the right regex.</p>
  
  <p>I have a PHP code like this:</p>
  
  <pre><code>foreach($res as $r) {
    $new_string = '&lt;a href="#" onclick="getMarkers(1,\\\' \\\',1);locate('.$r-&gt;latitude.','.$r-&gt;longitude.','.$r-&gt;zoom.','.$r-&gt;id.',0);"&gt;$0&lt;/a&gt;';
    $introduction = (preg_replace("/\b$r-&gt;title\b(?![^&lt;&gt;]*(?:&lt;|$))/i",$new_string,$introduction))
  }
  </code></pre>
  
  <p>This part of my code doesn't work:</p>
  
  <pre><code>preg_replace("/\b$r-&gt;title\b(?![^&lt;&gt;]*(?:&lt;|$))/i",$new_string,$introduction)
  </code></pre>
  
  <p>The problem is:
  This regex also change the avilable links what is in  HTML tag.</p>
  
  <p>Thank you for everybody patiente and I am wainting for the answers!</p>
  
  <p>Thanks!</p>
  
  <hr>
  
  <p><b>UPDATE</b>:
  I would like to say thank you for <a href="https://stackoverflow.com/users/1401975/hamza">HamZa</a> for this fantastic link!</p>
  
  <p><i>My solutions is:</i></p>
  
  <pre><code> $introduction = (preg_replace("/[^&gt;]*&gt;.*?&lt;\/a&gt;(*SKIP)(*FAIL)|$r-&gt;title/im",$new_string,$introduction));
  </code></pre>
  
  <p>Thanks for everybody! :)</p>