I’m looking for a single line regex which does the following:
Given a HTML tag with the ‘name’ attribute, I want to replace it with my own attribute. If that tag lacks the name attribute, I want to implant my own attribute. The result should look like this:
<IMG name='img1' ...> => <IMG name='myImg1' ...> <IMG ...> => <IMG name='myImg1' ...>
Can this be done with a single line regex?
The trick is to match every complete ‘attribute=value’ pair, but capture only the ones whose attribute name isn’t ‘name’. Then plug in your own ‘name’ attribute along with all the captured ones.