过滤上面str中的^hello.php?x1=11&x2=22和^bye.php?x3=33&x4=44 从 "1,这里是数据\"data1 is here\",这里是数据2^hello.php?x1=11&x2=22,这里是数据2^bye.php?x3=33&x4=44,1,2,3省略"; 得到 "1,这里是数据\"data1 is here\",这里是数据2,这里是数据,1,2,3省略"; 这样的结果
var str="1,这里是数据\"data1 is here\",这里是数据2^hello.php?x1=11&x2=22,这里是数据2^bye.php?x3=33&x4=44,1,2,3省略"; str=str.replace(/\^\w+\.php\?(\w+=\w+&)*(\w+=\w+)?/g,""); alert(str)
估计楼主是需要正则的非贪婪模式 <script type="text/javascript"> <!-- var str="1,这里是数据\"data1 is here\",这里是数据2^hello.php?x1=11&x2=22,这里是数据2^bye.php?x3=33&x4=44,1,2,3省略"; str=str.replace(/\^.*?,/g,","); alert(str) //--> </script>
try...<script type="text/javascript"> var test = "1,这里是数据\"data1 is here\",这里是数据2^hello.php?x1=11&x2=22,这里是数据2^bye.php?x3=33&x4=44,1,2,3省略"; var reg = /\^[^^,]*/g; var result = test.replace(reg, ""); document.write(result); </script>
"\^[^,]+"
replace
""
从
"1,这里是数据\"data1 is here\",这里是数据2^hello.php?x1=11&x2=22,这里是数据2^bye.php?x3=33&x4=44,1,2,3省略";
得到
"1,这里是数据\"data1 is here\",这里是数据2,这里是数据,1,2,3省略";
这样的结果
var str="1,这里是数据\"data1 is here\",这里是数据2^hello.php?x1=11&x2=22,这里是数据2^bye.php?x3=33&x4=44,1,2,3省略";
str=str.replace(/\^\w+\.php\?(\w+=\w+&)*(\w+=\w+)?/g,"");
alert(str)
<!--
var str="1,这里是数据\"data1 is here\",这里是数据2^hello.php?x1=11&x2=22,这里是数据2^bye.php?x3=33&x4=44,1,2,3省略";
str=str.replace(/\^.*?,/g,",");
alert(str)
//-->
</script>
var test = "1,这里是数据\"data1 is here\",这里是数据2^hello.php?x1=11&x2=22,这里是数据2^bye.php?x3=33&x4=44,1,2,3省略";
var reg = /\^[^^,]*/g;
var result = test.replace(reg, "");
document.write(result);
</script>