function convertHTML(str) {
var objA={'&':'&','<':'<','>':'>','\'':''','"':'\"'}
var matchStr = str.match(/([&|''|""|>|<])/g)
var matchStr1=''
for(var i=0; i<matchStr.length; ++i){
matchStr1 = str.replace(matchStr[i], objA[matchStr[i]])
}
return matchStr1;
}
console.log(convertHTML("Hamburgers < Pizza < Tacos "));
Output i'm getting is Hamburgers &​lt; Pizza < Tacos. I want Hamburgers &​lt; Pizza &​lt; Tacos. So is it possible to replace the second occurrence using this code with some changes ?.
[&|''|""|>|<]is not valid - you can't alternate inside a character class