I need a regular expression to match the following array of numbers, which can be nested. These should pass:
[]
[1, 2, 3]
[1, 2, 3, [1,2,3], 5]
but the following should fail the test:
abc
1
[1,2,3
[#]
This works:
/(^\[)(\d+\,|\s(?:(|\,))|\d+|\s\[|\]\,)*(\]$)/g
Is there are a better way to achieve the same result. I tried lookahead but don't fully understand it and couldn't get it to work.