Home > Blockchain >  remove everything within [] /\[[^][]*]/g
remove everything within [] /\[[^][]*]/g

Time:11-28

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);
<iframe name="sif1" sandbox="allow-forms allow-modals allow-scripts" frameborder="0"></iframe>

CodePudding user response:

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

    string = '[abcd]word[efg]';
    string = string.replace(/\[[^\]\[]*\]/g,"");
    console.log(string);
<iframe name="sif2" sandbox="allow-forms allow-modals allow-scripts" frameborder="0"></iframe>

  • Related