title: Regexp to turn <div><img ...></div> into <div><img ... /></div> in Python
body: <p>I'm trying to finish closing an image tag in the middle of some other HTML, since when I create it with JS, and then send it to myself, it isn't closed properly. I'm using Python for this.</p>
  
  <p>Given this string:</p>
  
  <pre><code>&lt;div&gt;&lt;img src="/images/someImage.png" alt="Some Image"&gt;&lt;/div&gt;
  </code></pre>
  
  <p>How can I get</p>
  
  <pre><code>&lt;div&gt;&lt;img src="/images/someImage.png" alt="Some Image" /&gt;&lt;/div&gt;
  </code></pre>
  
  <p>This is what I've come up with so far:</p>
  
  <pre><code>re.sub("&lt;img(.*)(?&lt;!/)&gt;", "&lt;img\\1 /&gt;", x)
  </code></pre>
  
  <p>And with just the image, it works, but once I add the <code>div</code>'s to surround it, it puts it in the wrong spot:</p>
  
  <pre><code>&lt;div&gt;&lt;img src="http://sh.local/images/tripAlbums/2014/thumbs/Background%20Default.jpeg"&gt;&lt;/div /&gt;
  </code></pre>
  
  <p>As you'll notice, the ending DIV has what I want on the image tag.</p>
  
  <p>Note that although I'm only showing one image, there may be more, so it should work with a global <code>re.sub</code>.</p>
  
  <p>Thanks.</p>