I get a string from an end point, the string will be in any of the forms as shown below
Input:
First Form
Option1[opt1,opt4,opt8,opt7],Option5[opt2,opt3],Option6[opt5,opt6]
Expected output:
[
Option1[opt1,opt4,opt8,opt7],
Option5[opt2,opt3],
Option6[opt5,opt6]
]
or
Option1[1,4,8,7],Option5[2,3],Option6[5,6]
Expected output:
[
Option1[1,4,8,7],
Option5[2,3],
Option6[5,6]
]
Second Form
Option1[opt1],Option5[opt2],Option6[opt6]
Expected output:
[
Option1[opt1],
Option5[opt2],
Option6[opt5]
]
or
Option1[1],Option5[2],Option6[6]
Expected output:
[
Option1[1],
Option5[2],
Option6[5]
]
Third Form
Option1,Option5,Option6 or Item1,Item2,Item3 or abc1,xyz2,ccc3
Expected output
[
Option1,
Option5,
Option6
]
for the Second and Third forms
.split(',')
works and returns expected array but here i am facing challenge with First form,
looking for some options (reg exp) that can consider , after ].
Note: Sorry for making changes in the question as i see input coming from endpoint is changing, but now i will not make any more edits for the inputs in the question