0

This regex is supposed to capture what's after the = sign and what's before the ).

Why does it return both the = and ) in the output. Is this how it works? Or am I doing something wrong?

const s = '=foo)';
console.log(s.match(/=(.*)\)/g))
Argee
  • 1,216
  • 1
  • 12
  • 22
Norman
  • 6,159
  • 23
  • 88
  • 141

1 Answers1

3

If you don't need to match multiple instances and you want to get what's in the capturing group then you get get rid of the g flag and retrieve solely the capturing group:

const s = '=foo)';
console.log(s.match(/=(.*)\)/)[1]);
blex
  • 24,941
  • 5
  • 39
  • 72
Aplet123
  • 33,825
  • 1
  • 29
  • 55