<textarea id="aaa">
/*
T
*/
var tmp = new Date();
</textarea>
<script>
alert(aaa.value.replace(/\/\*(.|\n)*?\*\//g, ""));
</script>

解决方案 »

  1.   

    (.|\n)*? 后面这个问号代表匹配模式是非贪婪的,也就是说尽可能少的匹配。如果不加这个问号的话,会将非注释部分一起匹配替换掉,下面就是不加的和加了的比较。<textarea id="aaa">
    /*
    T
    */
    var tmp = new Date();
    /*
    B
    */
    </textarea>
    <script>
    alert(aaa.value.replace(/\/\*(.|\n)*\*\//g, ""));
    alert(aaa.value.replace(/\/\*(.|\n)*?\*\//g, ""));
    </script>
      

  2.   

    .       匹配除换行符 \n之外的任何单字符。要匹配 .,请使用 \。 ...引自帮助文件你的RegExp之所以不能匹配的另外一个原因是,依上面所说,没有匹配\n,所以,找不到匹配,不能替换。
      

  3.   

    thanks,
    I ask you another question:
    how to find the next bracket that fits the current one?
    for example:
     (aa(bb(cc)dd)ee)ff