title: PHP preg_replace making regex optional?
body: <p>I have some content that I am trying to parse...</p>
  
  <p>I have html and with in the html I want to replace all my img tags with a custom string. Now one of the problems I have is that some content that comes in: the image tags is between a anchor.</p>
  
  <p>ex.</p>
  
  <pre><code>&lt;a href="link"&gt;&lt;img&gt;&lt;/a&gt;
  </code></pre>
  
  <p>The following code I have works...but I want it to be optional so in case no anchor tag is surrounded by a img tag does anyone have any good resource on regex or could help me out?</p>
  
  <p>Thank you!</p>
  
  <pre><code>$content = preg_replace('#&lt;a.*?&gt;'.$image_tag.'&lt;/a&gt;#i', "{$image_id}", $content);
  </code></pre>