javascript - dice up a string in JS -


i have string this

4741:green,cirhosis,orange,long-term,green,his b chic,4642:green,crhosis,green,hsysk b cc, 

the sting contains 2 records record id 4741 , 4642 separated character. within records else separated comma(,)

how can split sting. please note example string contains 2 records other ones may contain more or less or none. thank help!

basic idea:

var str = "4741:green,cirhosis,orange,long-term,green,his b chic,4642:green,crhosis,green,hsysk b cc,1111:asdf"  var re = /(\d+):([^(\d+:)]+)/g;  var matches = str.match(re);  for(var x in matches){     var parts = matches[x].split(":");     var id = parts[0];     var vals = parts[1].split(",");     alert(id + "\n" + vals.length); } 

Comments

Popular posts from this blog

ASP.NET/SQL find the element ID and update database -

jquery - appear modal windows bottom -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -