Replace all occurences of <img...> with <img.../> (add a slash).
var text = '<img src="a"> <img src="b" id="c"/>' text = text.replace(... your replacement ... ) // now text = '<img src="a"*!*/*/!*> <img src="b" id="c"/>'
Решение
Решение
An IMG tag with attributes can be represented as <img.*?>.
Now, how can we find an img, ending with /, but not with />? Think about it, maybe you can find a good way. At lease you’ll see which difficulties arise.
Another, easy and lazy way is to match <IMG.? in lazy mode until it ends with either /> or >, and then replace both types of tags with captured <IMG.? plus />.
Here’s the solution:
var text = '<img src="a"> <img src="b" id="c"/>' text = text.replace( /(<img.*?)\/?>/g, '$1/>' ) alert(text)
#284