javascript replace正则替换时调用函数替换的使用

以下函数将替换英文方式下的单引号和双引号,当然change函数编写决定了你要替换什么?

String.prototype.repSpecChar=function()
      {
      
        filterChar="'|"";//需要过滤的字符
           //var reg=new RegExp("(')|(")","g");
         var reg=new RegExp(filterChar,"gm");
         var newstr= this.replace(reg,change);
        return newstr;
        }
        function change(word)
        {
           if(word=="'") return "'";
           if(word==""") return """;
         }

原文地址:https://www.cnblogs.com/zwbgreat/p/3439523.html