I want to insert an ending slash before the closing bracket of every img
tag found in a string.
This (modified from here) is correctly returning the position of each instance of img
:
var re = /img\s/g,
match;
while (match = re.exec(str)) {
console.log(match.index); //
}
Knowing this, how can I find the next > after each img
and insert a / before it?