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

▲正则表达式替换的奇怪问题
为什么下面的代码没有替换成功?
<html   xmlns= "http://www.w3.org/1999/xhtml ">
<head>
<title>
css
</title>
</head>
<body>
<div> <a> </a> </div>
<script   type= "text/javascript ">
var   url   =   "http://bbs.test.com/read.php?tid=100 ";
var   key= "·   <a   href= 'http://bbs.test.com/read.php?tid=100 '> ×××××××× </a> <br> ";
var   reg   =   new   RegExp( "·   <a[^ <]*? "   +   url   +   "[^> ]*?> .*? </a> <br> ",   "i ");
key   =   key.replace(reg,   " ");
alert(key);
</script>
</body>
</html>

------解决方案--------------------
var url = "http://bbs.test.com/read.php\\?tid=100 ";
------解决方案--------------------
url = url.replace(/([\.\?\*\+\|])/g, "\\$1 ");