Split string with inner and outer delimeters in Javascript -
in javascript code, have string this:
"1943[15]43[67]12[32]"
i want return array this:
["1","9","4","3","15","4","3","67","1", 2","32"]
that is, want separate every character, except numbers inside brackets, want preserve 1 element.
is there elegant way this?
var str = '1943[15]43[67]12[32]', matches = str.match(/\d|\[\d+\]/g); (var = 0, matcheslength = matches.length; < matcheslength; i++) { matches[i] = matches[i].replace(/\d/g, ''); }; console.log(matches); // ["1", "9", "4", "3", "15", "4", "3", "67", "1", "2", "32"]
Comments
Post a Comment