正则表达式批量替换 单引号

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>正则表达式批量替换单引号'</title>
</head>
<body>
<input type="text" id="a" /><input type="button" value="ssss" onclick="th()" />
<script type="text/javascript">   
    function th() {
        var s = document.getElementById("a").value;
        alert(s);
        s = s.replace(/(\'*)/g, '');
        alert(s);
    }
</script>
</body>
</html>

/.../g  是正则表达式的属性, 表示全文匹配, 而不是找到一个就停止.

\'       是匹配转义过的 单引号 '  为防止出错。可以去掉 亲测。可行

\'*     是匹配有0个或多个 单引号

好了。可以去试试吧。

posted @ 2014-12-03 16:10  flyfishing  阅读(4651)  评论(0编辑  收藏  举报