I want to create an array out of a special string. The format is as follows:
(a),(b),(c(d,e)),(f(g(h,i,j)))
The array should be like this:
(a) | (b) | (c(d,e)) | (f(g(h,i,j)))
Using the split() function was not a good idea, as it gave me something like this:
(a) | (b) | (c(d | e)) | (f(g(h | i | j)))
Any ideas?
How about counting the number of open parenthesis? If the count is zero, you’re safe to split.
http://jsbin.com/otofog/1/
or alternatively (if you’re not targeting IE < 9):
http://jsbin.com/ohasuc/1/