title: RegEx for replacing and adding attributes to an HTML tag
body: <p>Given the following code :</p>
  
  <pre><code>&lt;body&gt;
    &lt;img src="source.jpg" /&gt;
    &lt;p&gt;
      &lt;img src="source.jpg" id ="hello" alt="nothing" /&gt;
      &lt;img src="source.jpg" id ="world"/&gt;
    &lt;/p&gt;
  &lt;/body&gt;
  </code></pre>
  
  <p>What's the best way - using a regular expression (or better?) - to replace it so it becomes this:</p>
  
  <pre><code>&lt;body&gt;
    &lt;img src="source.jpg" id="img_0" /&gt;
    &lt;p&gt;
      &lt;img src="source.jpg" id ="img_1"  alt="nothing" /&gt;
      &lt;img src="source.jpg" id ="img_2"/&gt;
    &lt;/p&gt;
  &lt;/body&gt;
  </code></pre>
  
  <p>In other words :</p>
  
  <ul>
  <li><p>All the <code>&lt;image /&gt;</code> tags all gets populated by an <code>id</code> attribute. </p></li>
  <li><p>The <code>id</code> attribute should contain an incremented attribute (this is not really the problem though as its just part of the replace procedure)</p></li>
  </ul>
  
  <p>I guess two passes are needed, one to remove all the existent <code>id</code> attributes and another to populate with new ones ?</p>