title: Python 3: How to add <p> before and after all img tags in html
body: <p>For the html, I need to add a p tag before and after img tabs.
  Each html includes multiple images.</p>
  
  <p>For example:</p>
  
  <pre><code>&lt;br&gt;&lt;img id="aimg_uhkH3" class="zoom" src="../Images/0001.jpg" border="0" alt="" width="430" height="20"&gt;&lt;br&gt;
  foo &lt;img id="acvdojj2" class="zoom" src="../Images/0002.jpg" width="430" height="20" border="0" alt=""&gt; foo 
  </code></pre>
  
  <p>Desired Result:</p>
  
  <pre><code>&lt;br&gt;&lt;p&gt;&lt;img id="aimg_uhkH3" class="zoom" src="../Images/0001.jpg" border="0" alt="" width="430" height="20"&gt;&lt;p&gt;&lt;br&gt;
  foo &lt;p&gt;&lt;img id="acvdojj2" class="zoom" src="../Images/0002.jpg" width="430" height="20" border="0" alt=""&gt;&lt;p&gt; foo
  </code></pre>
  
  <p>I fail to get it with regex.</p>
  
  <p>My Failed Code: (test_str is the html string)</p>
  
  <pre><code>re.sub(r'(&lt;img.*&gt;)','&lt;p&gt;\\1&lt;p&gt;',test_str)
  </code></pre>
  
  <p>My Failed Result:</p>
  
  <pre><code>&lt;br&gt;&lt;p&gt;&lt;img id="aimg_uhkH3" class="zoom" src="../Images/0001.jpg" border="0" alt="" width="430" height="20"&gt;&lt;br&gt;&lt;p&gt;
  foo &lt;p&gt;&lt;img id="acvdojj2" class="zoom" src="../Images/0002.jpg" width="430" height="20" border="0" alt=""&gt;&lt;p&gt; foo
  </code></pre>
  
  <p>Any hints? Thanks in advance.</p>