Nodejs String Replace replaceAll(str1, str2, ignore)

Here you can find the source of replaceAll(str1, str2, ignore)

Method Source Code

/**/*from w w w . j av a 2  s .c o m*/
 * String Util
 *
 * @author sanghyun moon <shmoon@amuzlab.com>
 * @version 1.0
 * @date 2016-08-07
 */
'use strict';

/* replaceAll */
String.prototype.replaceAll = function(str1, str2, ignore) 
{
    return this.replace(new RegExp(str1.replace(/([\/\,\!\\\^\$\{\}\[\]\(\)\.\*\+\?\|\<\>\-\&])/g,"\\$&"),(ignore?"gi":"g")),(typeof(str2)=="string")?str2.replace(/\$/g,"$$$$"):str2);
}

Related

  1. replaceAll(source, target)
    String.prototype.replaceAll = function (source, target) {
      return this.replace(new RegExp(source, "g"), target);
    };
    
  2. replaceAll(source,target)
    String.prototype.replaceAll = function(source,target){
      var val = this;
      while(val.indexOf(source)>-1){
        val = val.replace(source,target);
      return val;
    };
    
  3. replaceAll(str, replaceStr)
    'use strict';
    String.prototype.replaceAll = function(str, replaceStr) {
        return this.replace(new RegExp(str, 'gm'), replaceStr);
    };
    
  4. replaceAll(str, replacement)
    String.prototype.replaceAll = function(str, replacement) {
      var regex;
      regex = new RegExp(str, "ig");
      return this.replace(regex, replacement);
    };
    
  5. replaceAll(str1, str2, ignore)
    String.prototype.replaceAll = function(str1, str2, ignore) 
      return this.replace(new RegExp(str1.replace(/([\/\,\!\\\^\$\{\}\[\]\(\)\.\*\+\?\|\<\>\-\&])/g,"\\$&"),(ignore?"gi":"g")),(typeof(str2)=="string")?str2.replace(/\$/g,"$$$$"):str2);
    
  6. replaceAll(str1,str2)
    String.prototype.replaceAll= function(str1,str2){
        return this.replace(new RegExp(str1,"gm"),str2);  
    };
    
  7. replaceAll(strReplace, strWith)
    String.prototype.replaceAll = function(strReplace, strWith) {
        var reg = new RegExp(strReplace, 'ig');
        return this.replace(reg, strWith);
    };
    
  8. replaceAll(string, find, replace)
    function replaceAll(string, find, replace) {
      return string.replace(new RegExp(escapeRegExp(find), 'g'), replace);
    
  9. replaceAll(stringAntiga, stringNova)
    String.prototype.replaceAll = function (stringAntiga, stringNova) {
        return this.split(stringAntiga).join(stringNova);
    };