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