-2

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, "");
Antonino
  • 2,937
  • 3
  • 22
  • 37

1 Answers1

1

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

Code Maniac
  • 35,187
  • 4
  • 31
  • 54