easy/direct replacements
428203
protected function _directReplacements($string)
    {
        foreach ($this->DIRECT_NUMS as $dn => $dn_replacement) {
            $string = preg_replace("/$dn/i", $dn_replacement, $string);
        }
        return $string;
    }
850037
function applyReplacements(str, replacements) {
    var result = "",
        replacement,
        i;

    for (i = 0; i < replacements.length; i++) {
        replacement = replacements[i];
        if (replacement) {
            result += replacement.newStr;
            i += replacement.oldStr.length - 1;
        } else {
            result += str.charAt(i);
        }
    }

    result += str.substr(i, str.length);

    return result;
}
1209623
def replace_in_files(search, replace, depth=0, paths=None, confirm=True):
    

    # have the user select some files
    if paths==None:
        paths = _s.dialogs.MultipleFiles('DIS AND DAT|*.*')
    if paths == []: return

    for path in paths:
        lines = read_lines(path)

        if depth: N=min(len(lines),depth)
        else:     N=len(lines)

        for n in range(0,N):
            if lines[n].find(search) >= 0:
                lines[n] = lines[n].replace(search,replace)
                print(path.split(_os.path.pathsep)[-1]+ ': "'+lines[n]+'"')

        # only write if we're not confirming
        if not confirm:
            _os.rename(path, path+".backup")
            write_to_file(path, join(lines, ''))

    if confirm:
        if input("yes? ")=="yes":
            replace_in_files(search,replace,depth,paths,False)

    return
1022102
function copyReplace( src, dest, replacements ){

        if ( replacements ){
            var source = grunt.file.read( src );
            for ( var s in replacements ){
                var r = replacements[s];
                var re = new RegExp( s, "g" );
                source = source.replace( re, r );
            }
            grunt.file.write( dest, source );
        }
        else{
            grunt.file.copy( src, dest );
        }

	}
790000
def replace_one(cls, filter, replacement, upsert=False):
        
        return cls.collection.replace_one(
            filter, replacement, upsert
        ).raw_result
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);
            });
        };
    });

}
342994
function replacements(document, original) {
  var modified = moment().format('YYYY-MM-DD');
  var result = original;
  result = tagReplace(result, 'EOL', '\n');
  result = tagReplace(result, 'ID', document.metadata.id);
  result = tagReplace(result, 'TITLE', document.metadata.title);
  result = tagReplace(result, 'SERIES', document.metadata.series);
  result = tagReplace(result, 'SEQUENCE', document.metadata.sequence);
  result = tagReplace(result, 'COPYRIGHT', document.metadata.copyright);
  result = tagReplace(result, 'LANGUAGE', document.metadata.language);
  result = tagReplace(result, 'FILEAS', document.metadata.fileAs);
  result = tagReplace(result, 'AUTHOR', document.metadata.author);
  result = tagReplace(result, 'PUBLISHER', document.metadata.publisher);
  result = tagReplace(result, 'DESCRIPTION', document.metadata.description);
  result = tagReplace(result, 'PUBLISHED', document.metadata.published);
  result = tagReplace(result, 'GENRE', document.metadata.genre);
  result = tagReplace(result, 'TAGS', document.metadata.tags);
  result = tagReplace(result, 'CONTENTS', document.metadata.contents);
  result = tagReplace(result, 'SOURCE', document.metadata.source);
  result = tagReplace(result, 'MODIFIED', modified);
  return result;
}
1354617
def replace_in_files(dirname, replace):
    """"""
    filepath = os.path.abspath(dirname / "requirements.in")
    if os.path.isfile(filepath) and header_footer_exists(filepath):
        replaced = re.sub(Utils.exp, replace, get_file_string(filepath))
        with open(filepath, "w") as f:
            f.write(replaced)
        print(color(
            "Written to file: {}".format(filepath),
            fg='magenta', style='bold'))
359486
def replace(code, pattern, goal):
    """"""
    finder = similarfinder.RawSimilarFinder(code)
    matches = list(finder.get_matches(pattern))
    ast = patchedast.get_patched_ast(code)
    lines = codeanalyze.SourceLinesAdapter(code)
    template = similarfinder.CodeTemplate(goal)
    computer = _ChangeComputer(code, ast, lines, template, matches)
    result = computer.get_changed()
    if result is None:
        return code
    return result
897186
function replacer(match, quote, require) {
        var replacement = 'require(' + quote;
        try {
            resolve.sync(require);
        } catch (exc) {
            try {
                // Try to resolve the require statement starting from the root folder
                resolve.sync(require, {paths: ['.']});
                replacement += relativeToRoot + path.sep;
            } catch (exc2) {
            }
        }
        replacement += require + quote + ')';
//        console.log(replacement);
        return replacement;
    }
67350
public function directReplace(){
		$args = func_get_args();

		$replace = is_array($args[0]) ? $args[0] : array($args[0] => $args[1]);

		foreach($replace as $key => $val){
			$this->_direct_replace[$key] = $val;
		}

		return $this;
	}
1062985
def replace_types(text):
    """"""
    if not hasattr(replace_types, '_replacer'):
        replace_types._replacer = build_replacer()
    return replace_types._replacer(text)
1331106
def replace(self, ):
        
        tfi = self.get_taskfileinfo_selection()
        if tfi:
            self.reftrack.replace(tfi)
396981
def replace(self, target):
        
        if sys.version_info < (3, 3):
            raise NotImplementedError("replace() is only available "
                                      "with Python 3.3 and later")
        if self._closed:
            self._raise_closed()
        self._accessor.replace(self, target)
347342
def replace(self):
        

        replacement = self._tw.tasks.filter(' '.join(self._uuids))
        self.__class__ = replacement.__class__
        self.__dict__ = replacement.__dict__
676359
function replacePlaceholders(src, options) {
	return Object.keys(placeholders).reduce((out, placeholder) => {
		return out.replace(new RegExp(`${placeholder}`, 'g'), placeholders[placeholder]);
	}, src);
}
139815
function replace(haystack, needle) {
			const replacement = options.resolve ? notate(data, needle.trim()) : data[needle.trim()];

			return VALID_RESULT_TYPES.includes(typeof replacement) ? replacement : options.clean ? '' : haystack;
		}