title: How to match start and end tag and anything between them including white space using regex?
body: <p>I have html content stored in my database and what i need to do is that i have to get this content and match for anchor tag and replace that anchor tag with any string.</p>
  
  <p>Let say I have following html stored in my wordpress database.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>      &lt;h3&gt;Complications&lt;/h3&gt;
        &lt;p&gt;&lt;strong&gt;The three most common serious gastric sleeve complications&lt;/strong&gt; are:&lt;/p&gt;
        &lt;ul&gt;
           &lt;li&gt;
           &lt;a href="https://insights.ovid.com/pubmed?pmid=28938270" target="_blank"&gt;3&lt;/a&gt;
              &lt;span&gt;&lt;a href="javascript:;" class="list_expand"&gt;Staple line leaks&lt;/a&gt; -  2.1% of patients on average (between 1.09% and 4.66%, depending on the study) experience staple line leaks (&lt;a href="#reference-box"&gt;9&lt;/a&gt;) (&lt;a href="#reference-box"&gt;10&lt;/a&gt;)&lt;/span&gt;
              &lt;div class="list_expand_content blockquote"&gt;&lt;/div&gt;
           &lt;/li&gt;
           &lt;li&gt;
              &lt;span&gt;&lt;a href="javascript:;" class="list_expand"&gt;Bleeding&lt;/a&gt; - 1.2% of patients (&lt;a href="#reference-box"&gt;11&lt;/a&gt;)&lt;/span&gt;
              &lt;div class="list_expand_content blockquote"&gt;&lt;/div&gt;
           &lt;/li&gt;
           &lt;li&gt;
              &lt;span&gt;&lt;a href="javascript:;" class="list_expand"&gt;Stenosis/Strictures&lt;/a&gt; -  0.6% of patients (&lt;a href="#reference-box"&gt;12&lt;/a&gt;)&lt;/span&gt;
              &lt;div class="list_expand_content blockquote"&gt;&lt;/div&gt;
           &lt;/li&gt;
        &lt;/ul&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>and what i need to do is that I have to match anchor tag which is like </p>
  
  <pre><code>&lt;a anthing goes here&gt;[0-999]&lt;/a&gt; 
  </code></pre>
  
  <p>and replace that anchor tag with shortcode like [ref link= 'link which is wrapped inside each anchor tag' number='number wrapped between starting and closing anchor tag'].</p>
  
  <p>I wrote following code for match the value and get the value.</p>
  
  <p><code>preg_match_all('/&lt;a[^&gt;]+&gt;(\d{1,3})&lt;\/a&gt;/',$content,$matches, PREG_PATTERN_ORDER);</code> </p>
  
  <p>but what about replacing that value with shortcode in database.</p>