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

正则中括号问题
var   ys   =   "abcdef ";
str   =   "[yy]abcdef[/yy]123456 ";
var   reop   =   new   RegExp( "[yy] "+ys+ "[/yy] ", "ig ");
reop   =   str.replace(reop, " ");

这段执行后没效果.............
问题在[]这个上面
但不知道怎么解决
请帮忙解决一下,谢谢

------解决方案--------------------
var reop = new RegExp( "\\[yy\\] "+ys+ "\\[\\/yy\\] ", "ig ");
------解决方案--------------------
$()*+.[?\^{}|
这些字符都要加斜杠
------解决方案--------------------
<script language= "javascript ">
var ys = "abcdef ";
str = "[yy]abcdef[/yy]123456 ";
var reop = new RegExp( "\\[yy\\] "+ys+ "\\[\\/yy\\] ", "ig ");
reop = str.replace(reop, " ");
alert (reop)
</script>
去掉 "[yy]abcdef[/yy]123456“?