日期:2014-05-16  浏览次数:20315 次

js正则表达式问题
"whe":"%20and%20s7%20in(1,2,3,4,5,40,39,38,37,36)%20","FDSFS":"FSS,SS"
如何通过正则表达式,将“,”前后的字符串分割出来,返回字符串数组,求大神
"whe":"%20and%20s7%20in(1,2,3,4,5,40,39,38,37,36)%20"和
"FDSFS":"FSS,SS"

------解决方案--------------------
var aa = '"whe":"%20and%20s7%20in(1,2,3,4,5,40,39,38,37,36)%20","FDSFS":"FSS,SS"';
aa = aa.replace(/(?:\")(\,)+(?:\")/g,"\"\"$1\"\"").split(/\"\,\"/);
console.log(aa[0]);
console.log(aa[1]);
console.log(aa.length);


试试,代码虽说不是很优的。。。
暂时只能想到这个。
------解决方案--------------------
var $a = '"whe":"%20and%20s7%20in(1,2,3,4,5,40,39,38,37,36)%20", "FDSFS":"FSS,SS"';
var $r = /, /;
var $b = $a.split($r);

------解决方案--------------------
没什么好方法。
var s= '"whe":"%20and%20s7%20in(1,2,3,4,5,40,39,38,37,36)%20","FDSFS":"FSS,SS"';
var x=s.split(/\",\"/g);
alert(x[0]+"\"");
alert("\""+x[1]);