Nodejs String Replace replaceAll(find, replace)

Here you can find the source of replaceAll(find, replace)

Method Source Code

String.prototype.replaceAll = function (find, replace) {
    var str = this;
    return str.replace(new RegExp(find.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&'), 'g'), replace);
};

Related

  1. replaceAll(de, para)
    String.prototype.replaceAll = function (de, para) {
      var str = this;
      var pos = str.indexOf(de);
      while (pos > -1) {
        str = str.replace(de, para);
        pos = str.indexOf(de);
      return (str);
    };
    ...
    
  2. replaceAll(exp, newStr)
    String.prototype.replaceAll = function (exp, newStr) {
        return this.replace(new RegExp(exp, "gm"), newStr);
    };
    
  3. replaceAll(f,r)
    String.prototype.replaceAll = function(f,r) {
        return this.split(f).join(r);
    };
    
  4. replaceAll(find, replace)
    String.prototype.replaceAll = function (find, replace) {
        var str = this;
        return str.replace(new RegExp(find, 'g'), replace);
    };
    
  5. replaceAll(find, replace)
    String.prototype.replaceAll = function(find, replace) {
      return this.replace(new RegExp(find, 'g'), replace);
    };
    
  6. replaceAll(find, replace)
    function escapeRegExp(string) {
        return string.replace(/([.*+?^=!:${}()|\[\]\/\\])/g, "\\$1");
    String.prototype.replaceAll = function (find, replace) {
        return this.replace(new RegExp(escapeRegExp(find), 'g'), replace);
    
  7. replaceAll(find, replace)
    String.prototype.replaceAll = function (find, replace) {
      return this.replace(new RegExp(find, 'g'), replace);
    };
    
  8. replaceAll(find, replace)
    String.prototype.replaceAll = function(find, replace){
      find = find.escapeRegExp();
      return this.replaceAllRegExp(find, replace);
    };
    
  9. replaceAll(find, replace)
    String.prototype.replaceAll = function (find, replace) {
      return this.replace(new RegExp(find, 'g'), replace);
    };
    String.prototype.sanitize = function () {
      var s = this.replace(/\W+/g, "");
      return s;
    };