I have string which contain 5 to 6 word and i would like to replace some word with highlighter style.
$(document).ready(function() {
var str = "Micromax Samsung S3 Microsoft Galaxy S";
var arr = ["Micro", "s"];
arr.forEach(function(item) {
str = str.replace(new RegExp(item.replace(/\+/g, "\\+"), "g"), '<span class="red">'+ item +'</span>');
})
$('#dvHtml').html(str);
});
But i am getting every s in the entire string including but i don't want to replace .
Can any body help me to exclude or ignore following items from replace
<span class="red"></span>
Output should be
Now this will replace Micro with <span class="red">Micro</span> and s with <span class="red">s</span>
Following are output
