DerFrederikHD
DerFrederikHD

Reputation: 11

remove everything within [] /\[[^][]*]/g

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

Answers (1)

Raz Luvaton
Raz Luvaton

Reputation: 3780

You can use this: \[[^\]\[]*\] (you forgot some escaping)

    string = '[abcd]word[efg]';
    string = string.replace(/\[[^\]\[]*\]/g,"");
    console.log(string);

Upvotes: 1

Related Questions