0

I've got this regex to search a string and replace a specific image if found, but the regex replace never works.

Here's the code I'm using.

var txt = '<img src="images/p.gif" alt="" onload="" />'+
          '<img src="images/p2.gif" alt="" onload="" />'+
          '<img src="images/p.gif" alt="" />';

var re = txt .replace(/<img src=\"images\/p\.gif\"[^>]*>/g, '');
alert(re);
Chaosxmk
  • 774
  • 14
  • 28
  • which browser you using? it works for me in Google Chrome – Roman Mar 27 '14 at 12:47
  • 2
    [Obligatory don't parse _HTML_ with _RegExp_ link](http://stackoverflow.com/a/1732454/1615483) – Paul S. Mar 27 '14 at 12:48
  • I'm testing in firefox and chrome. I'm either having all images erased, and no images. And while I would love to not regex this, the image I've trying to erase is going to have an onload function attached to it and turning it into dom content would run said function. – Chaosxmk Mar 27 '14 at 12:52
  • @Chaosxmk both firefox and chrome shows me alert with this string: – Roman Mar 27 '14 at 12:56
  • If that is your exact input and regex, I don't see why it doesn't work. – aliteralmind Mar 27 '14 at 12:56
  • I figured out the problem. My testing text was simply `` whereas the live version was `` – Chaosxmk Mar 27 '14 at 13:11

0 Answers0