Solved it in case anyone needs it here it is
var feed = feeds.entries[i].content; var parsedFeed = feed.replace(/src=/gi, "tempsrc="); var tmpHolder = document.createElement('div'); tmpHolder.innerHTML=parsedFeed;
I have a string containing html markup which include <img src='path.jpg'/>
I would like to run a regex against the string to replace every src attr to tmpSrc
so
<img src='path.jpg'/>
would turn into
<img tmpSrc='path.jpg'/>
this is in javascript by the way
and here is the root issue posted in other places but has not been solved
Browser parse HTML for jQuery without loading resources
How to parse AJAX response without loading resources?
Thanks
If this is a string you control and not HTML retrieved from a web page, then you can indeed safely use a regex. To change all occurences of
<img src=to<img tmpSrc=, you can use this operation:What the other posters have been saying is that regex are not good to use on HTML retrieved from a web page because different browsers return different forms of HTML so it makes it hard to reliably match it. But, if the string you’re trying to do a replace on is under your own control and you can know the format of it, then this regex should work fine.