-1

Given this input:

[[00], [01], [02], [03]]

I'm trying to extract all the values inside the [ ].

The regex I've crafted looks like this /[^[\]]+(?=])/g But if I try in on my input, it only returns the first element

$ /[^[\]]+(?=])/g.exec(' [[00], [01], [02], [03]]');

$ [ '00', index: 3, input: ' [[00], [01], [02], [03]]' ]

What I don't understand is I've built the regex and tested it on https://regex101.com/r/QhZDMR/1, and on there it seems to return all the values just fine.

Community
  • 1
  • 1
Laurier
  • 1
  • 2

1 Answers1

0

exec function finds only the first match. Instead use match like this:

"[[00], [01], [02], [03]]".match(/[^[\]]+(?=])/g)
Ec_
  • 66
  • 5