arrays - Restrict string split between particular values javascript -


i have string

var str = "error,#ffffff,won,25,[{\"color\":\"#7ac1de\",\"from\":\"10\",\"to\":\"60\"}]" 

i splitting string based on comma (',') in string. need split string out affecting comma inside [{\"color\":\"#7ac1de\",\"from\":\"10\",\"to\":\"60\"}].

so expected output ['error', '#ffffff', 'won', '25', '[{"color":"#7ac1de","from":"10","to":"60"}]'] .
i tried many ways not working. please me.

something ?

var str = "error,#ffffff,won,25,[{\"color\":\"#7ac1de\",\"from\":\"10\",\"to\":\"60\"}]";    var split = str.split(/,(?![^{]*})/);    console.log(split);

regex source


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -