Replace a word with the updated word.

@param  {Object}   replaceMap
@param  {Object}   keepMap
@param  {Array}    rules
@return {Function}
559854
function replaceWord(replaceMap, keepMap, rules) {
        return function (word) {
            // Get the correct token and case restoration functions.
            var token = word.toLowerCase();
            // Check against the keep object map.
            if (keepMap.hasOwnProperty(token)) {
                return restoreCase(word, token);
            }
            // Check against the replacement map for a direct word replacement.
            if (replaceMap.hasOwnProperty(token)) {
                return restoreCase(word, replaceMap[token]);
            }
            // Run all the rules against the word.
            return sanitizeWord(token, word, rules);
        };
    }
411335
function replaceAll(str = '', pattern, replacement) {
	if (arguments.length < 2 ){
		return str;
	}

	let rs = str;
	if (lodash.isPlainObject(pattern)){
		for (let key in pattern){
			rs = rs.replace(new RegExp('{' + key + '}', "gm"), pattern[key])
		}
	}else {
		rs = rs.replace(new RegExp(pattern, "gm"), replacement)
	}

	return rs;
}
284880
public static String replaceStrByMap(Map<String, String> requestParameters,
            String sourceContent) {

        String contentAfterReplace = sourceContent;

        for (Entry<String, String> entry : requestParameters.entrySet()) {

            String sourceContentHelperNew = contentAfterReplace;
            String varName = entry.getKey();
            String replacement = entry.getValue();

            if (varName.contains(PcConstants.NODE_REQUEST_PREFIX_REPLACE_VAR)) {

                String varTrueName = "$"
                        + varName
                                .replace(
                                        PcConstants.NODE_REQUEST_PREFIX_REPLACE_VAR,
                                        "");
                sourceContentHelperNew = contentAfterReplace.replace(
                        varTrueName, replacement);
                contentAfterReplace = sourceContentHelperNew;
            }

        }

        return contentAfterReplace;
    }
1106465
function replace(string, pattern, replacement) {
    var isReplaced = false;

    var result = string.replace(pattern, function () {
      isReplaced = true;

      // arguments are $0, $1, ..., offset, string
      return Array.prototype.slice.call(arguments, 1, -2)
        .reduce(function (pattern, match, index) {
          // '$1' from strings like '$11 $12' shouldn't be replaced.
          return pattern.replace(
            new RegExp('\\$' + (index + 1) + '(?=[^\\d]|$)', 'g'),
            match
          );
        }, replacement);
    });

    if (!isReplaced) {
      throw new Error(
        format(
          'we couldn\'t replace pattern: \'%s\' with value: \'%s\' ' +
          'in file: \'%s\'',
          pattern, replacement, path
        )
      );
    }
    return result;
  }
1056948
def add(self, rule: 'functions.ReplacementRule') -> None:
        
        self.matcher.add(rule.pattern, rule.replacement)
136056
function replace() {

    if (!isOriginal) return;
    else isOriginal = false;

    function replaceWith(fn) {
        return function() {
            /* eslint prefer-rest-params:0 */
            // todo: once node v4 support dropped, use rest parameter instead
            fn.apply(logger, Array.from(arguments));
        };
    }

    ['log', 'debug', 'info', 'warn', 'error'].forEach((lvl) => {
        console[lvl] = function() {
            Array.prototype.slice.call(arguments).forEach((arg) => {
                write(lvl == "error" ? process.stderr : process.stdout, lvl, arg);
            });
        };
    });

}
629273
private Map<String, String> replaceInMapValues(Map<String, String> map,
                                                   String oldVal,
                                                   String newVal) {
        for (String key : map.keySet()) {
            String value = map.get(key);
            if (value.contains(oldVal)) {
                value = StringUtils.replace(value, oldVal, newVal);
                map.put(key, value);
            }
        }
        return map;
    }
712914
function replace(a, elt1, elt2) {
  var idx = a.indexOf(elt1);
  if (idx !== -1) { a[idx] = elt2; }
  return a;
}
724917
function replaceString(content, search, replace) {
        var index = 0;

        do {
          index = content.indexOf(search, index);

          if (index !== -1) {
            content = content.substring(0, index) + replace + content.substr(index + search.length);
            index += replace.length - search.length + 1;
          }
        } while (index !== -1);

        return content;
      }
1048002
function sanitizeWord(token, word, rules) {
        // Empty string or doesn't need fixing.
        if (!token.length || uncountables.hasOwnProperty(token)) {
            return word;
        }
        var len = rules.length;
        // Iterate over the sanitization rules and use the first one to match.
        while (len--) {
            var rule = rules[len];
            if (rule[0].test(word))
                return replace(word, rule);
        }
        return word;
    }
775314
function(key, replacements) {
        var message = messageMap[key];

        if (replacements) {
            message = util.replaceText(message, replacements);
        }

        return message;
    }
341218
public String replace(Map<String, String> varMap)
   {
      StringBuilder newString = new StringBuilder();

      int p = 0;
      int p0 = 0;
      while (true)
      {
         p = templateText.indexOf("${", p);
         if (p == -1)
         {
            newString.append(templateText.substring(p0, templateText.length()));
            break;
         }
         else
         {
            newString.append(templateText.substring(p0, p));
         }
         p0 = p;
         p = templateText.indexOf("}", p);
         if (p != -1)
         {
            String varName = templateText.substring(p0 + 2, p).trim();
            if (varMap.containsKey(varName))
            {
               newString.append(varMap.get(varName));
               p0 = p + 1;
            }
         }
      }
      return newString.toString();
   }
630584
def replace(oldEl, newEl):
        # type: (Union[Rule, _RuleConnectable], Union[Rule, _RuleConnectable]) -> Union[Rule, _RuleConnectable]
        
        if isinstance(oldEl, Rule):
            return Manipulations.replaceRule(oldEl, newEl)
        if isinstance(oldEl, (Nonterminal, Terminal)):
            return Manipulations.replaceNode(oldEl, newEl)
1293003
protected static function transformReplacement(array $words, $replace)
    {
        return array_map(function ($value) use ($replace) {
            return str_repeat($replace, mb_strlen($value));
        }, $words);
    }
1034893
async function replace(string, regex, callback) {
	regex.lastIndex = 0;

	/* get all data */
	const promises = [];
	string.replace(regex, (match, ...args) => {
		const promise = callback(match, ...args);
		promises.push(promise);
	});
	const data = await Promise.all(promises);

	/* replace all data */
	return data.length ? string.replace(regex, () => data.shift()) : string;
}
984030
function _replaceRegex (cartoError, listedError) {
  if (!listedError.friendlyMessage) {
    return cartoError.message;
  }
  var match = cartoError.message && cartoError.message.match(listedError.messageRegex);
  if (match && match.length > 1) {
    var replaced = listedError.friendlyMessage.replace('$0', match[1]);
    if (match.length > 2) {
      replaced = replaced.replace('$1', match[2]);
    }
    return replaced;
  }
  return listedError.friendlyMessage;
}
940153
public String replace(String word) {
        int flags = 0;
        if (ignoreCase) {
            flags = flags | Pattern.CASE_INSENSITIVE;
        }
        return Pattern.compile(pattern, flags).matcher(word).replaceAll(replacement);
    }