You can use substr and replace in a loop to delete all texts that are within [ ]
For example, if you try 'Javier [the best] of [your home in] Panama' , the result will be Javier de Panama
Then we eliminate all repeated spaces with the code
output.replace(/\s+/g,' ').trim();
I hope you serve
var example = document.getElementById('example'),
result = document.getElementById('result');
example.addEventListener('keyup',function() {
var output = this.value,
finish = false;
while(!finish) {
if(output.indexOf('[') >=0 && output.indexOf(']') >= 0) {
output = output.replace(output.substr(output.indexOf('['), output.indexOf(']') - output.indexOf('[') + 1),'');
}
else {
finish = true;
}
}
result.innerText = output.replace(/\s+/g,' ').trim();
});
<input type="text" id="example" />
<span id="result"></span>