title: SED Regex rewriting between two patterns using backreferences
body: <p>I have text in many html files that is in this format:</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;!-- BEGIN FOOTER --&gt;
  &lt;div id="footer"&gt; 
    &lt;p align="right"&gt; Slogan&lt;br /&gt;
      5555 Street East &lt;br /&gt;
      City, State 99999 &lt;br /&gt;
      Call Us (555)555-5555 &lt;br /&gt;
  &lt;/p&gt;
      
  &lt;div align="center"&gt;
  &lt;a class="footer" href="http://www.example.com" title="Site"&gt;Site&lt;/a&gt;
  &lt;/div&gt;
  
  
   &lt;br&gt;
  
  &lt;/div&gt;
  &lt;!--END FOOTER--&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>I am using this:</p>
  
  <pre><code>sed -E -i 's/(&lt;!-- BEGIN FOOTER --&gt;)(.|\n)*(&lt;!--END FOOTER--&gt;)/\1 &lt;br&gt;REPLACE&lt;br&gt; \3 /m'  file.html
  </code></pre>
  
  <p>but not working to capture &amp; backreference them:</p>
  
  <pre><code>\1 &lt;!-- BEGIN FOOTER --&gt; 
  \3 &lt;!--END FOOTER--&gt; 
  </code></pre>
  
  <p>And insert this in between them:</p>
  
  <pre><code>REPLACE
  </code></pre>
  
  <p>So trying to end up with this:</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;!-- BEGIN FOOTER --&gt;
  &lt;br&gt;REPLACE&lt;br&gt;
  &lt;!--END FOOTER--&gt;</code></pre>
  </div>
  </div>
  </p>