javascript - regex for images and replace
HTML
<div class="info"></div>
JavaScript
var data = 'some new text before.... <img class="text" src="http://mail.rediff.com/pic/o/smiley.gif" title="text"/>',
rex = /<img[^>].*?src="(.*?)smiley\.gif"\s.*?\/>/g;;
function escapeRegExp(string){
return string.replace(/([.*+?^=!:${}()|\[\]\/\\])/g, "\\$1");
}
var custSimleys = {"laugh" : "smiley.gif"}
var custSimleysVal = {"laugh" : ":)"}
var regex = new RegExp('<img[^>].*?src="(.*?)'+escapeRegExp(custSimleys.laugh)+'".*?\/>', 'g');
console.log(regex);
var newdata2 = data.replace(regex,custSimleysVal.laugh);
$(".info").append("<br/>---> data: " + data );
$(".info").append("<br/>--->2: " + newdata2 );