title: php regex match & replace html a tags exclude domain
body: <p>I found links and replace with nofollow. But I need if &quot;&lt;a(.*)&quot; line contains &quot;google.com&quot; stop replace.</p>
  <p>This is my code:</p>
  <pre><code>preg_replace('#(&lt;a\s)#is', '\\1rel=&quot;nofollow noreferrer ugc&quot; target=&quot;_blank&quot; ', $post-&gt;content);
  </code></pre>
  <p>Inputs:</p>
  <pre><code>&lt;a href=&quot;https://www.burtinet.com/&quot;&gt;Hosting&lt;/a&gt;
  &lt;a href=&quot;https://www.google.com/&quot;&gt;Search&lt;/a&gt;
  </code></pre>
  <p>Output:</p>
  <pre><code>&lt;a rel=&quot;nofollow noreferrer ugc&quot; target=&quot;_blank&quot; href=&quot;https://www.burtinet.com/&quot;&gt;Hosting&lt;/a&gt;
  &lt;a rel=&quot;nofollow noreferrer ugc&quot; target=&quot;_blank&quot; href=&quot;https://www.google.com/&quot;&gt;Search&lt;/a&gt;
  </code></pre>
  <p>I need:</p>
  <pre><code>&lt;a rel=&quot;nofollow noreferrer ugc&quot; target=&quot;_blank&quot; href=&quot;https://www.burtinet.com/&quot;&gt;Hosting&lt;/a&gt;
  &lt;a href=&quot;https://www.google.com/&quot;&gt;Search&lt;/a&gt;
  </code></pre>