正则替换问题
var str = "aaaa|bbbb|cccc ";
var chas = [ "aaaa "],[ "bbbb "],[ "cccc "];
for(var i=0;i <chas.length;i++){
str = str.replace(/ "+chas[i]+ "/ig, "test ");
}
上面的执行后替换不起作用
问题出在/ "+chas[i]+ "/ig这里
请正确的应该怎么写?
------解决方案--------------------var str = "aaaa|bbbb|cccc ";
var chas = [[ "aaaa "],[ "bbbb "],[ "cccc "]];
for(var i=0;i <chas.length;i++){
var cc=new RegExp(chas[i], "ig ")
str = str.replace(cc, "test ");
}
alert(str);