With this code I search in a string
the indexes of "["
and "]"
and then delete what is inside them with a replace
, but I also need remove the brackets , how should I do it? , because it does not eliminate them in my example ...
var a = "Hola[x]fsaaf fsa";
var b = a.indexOf("[");
var c = a.indexOf("]");
var mostrar = a.substring(b, c +1);
var name = a.replace(new RegExp(mostrar, 'g'), "");
console.log(name);
Also try, something that I really know what it means, this:
var a = "Hola[x]fsaaf fsa";
var b = a.indexOf("["); // 6
var c = a.indexOf("]"); // 16
var mostrar = a.substring(b, c +1);
var name = a.replace(regex, "");
var regex = new RegExp('\[?\b(?:' + mostrar + ')\b\]?', 'gi');
console.log(name);
But it leaves me the same string ...