Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JS Regex to remove IMG Tag from String

I have a String from a tabel innerHTML where i need to remove all img tags using replace my Regex removes everthing after the first img tag my code at JSFiddle here

like image 902
Zion Avatar asked Aug 17 '15 08:08

Zion


1 Answers

Use non-greedy matching using .*?

var tmp = inner.replace(/<img .*?>/g,"REPLACED"); 

Regex Demo

like image 74
nu11p01n73R Avatar answered Oct 18 '22 19:10

nu11p01n73R