Reputation: 11
Im trying to remove everything that is inside this: [] To example [abcd]word[efg] should be word. I tried to replace it like this but its not working for some reason. Does anyone know how to fix that?
string = '[abcd]word[efg]';
string = string.replace(/\[[^][]*]/g,"");
console.log(string);
Upvotes: 0
Views: 44
Reputation: 3780
You can use this: \[[^\]\[]*\]
(you forgot some escaping)
string = '[abcd]word[efg]';
string = string.replace(/\[[^\]\[]*\]/g,"");
console.log(string);
Upvotes: 1