I am able to achieve the same functionality using the regex / *\(\w+\) */g
but i wanted to know what does [^)] do in the following regex expression
let str = "Hello, this is Mike (example)";
str.replace(/ *\([^)]*\) */g, "");
I am able to achieve the same functionality using the regex / *\(\w+\) */g
but i wanted to know what does [^)] do in the following regex expression
let str = "Hello, this is Mike (example)";
str.replace(/ *\([^)]*\) */g, "");
In [] ( character class ) ^ means negation.
so this means [^)]+ Match anything except )
let str = "Hello, this is Mike (example)";
let op = str.replace(/ *\([^)]*\) */g, "");
console.log(op)
For more info you can read here Character class and negation