我得到一个字符串:str ="color:red,blue;shape:正方形;size:5,12;"我想得到的是color,shape,size这些属性和他们对应的值,我的思路是先根据";"(分号)把他们分开,再根据“:”(冒号)把他们分开,最后根据“,”(逗号)把他们分开,split这个貌似不行啊,
var str = "color:red,blue;shape:正方形;size:5,12;"var reg = /([^::;;]+)[::\s]+([^::;;]*)/g;while(reg.exec(str)){ console.log(RegExp.$1 + ": " + RegExp.$2);}