This is in internal method that replaces a certain 'pattern' in the
        provided command with a 'replacement'.
        A different replacement can be specified when the pattern occurs right
        at the beginning of the command.
760602
def replaceInCommand(self,command, pattern, replacement, replacementAtBeginning):
        
        # Turn the command into a list:
        commandAsList = list(command)
        # Get the indices of the pattern in the list:
        indices = [index.start() for index in re.finditer(pattern, command)]
        # Replace at the indices, unless the preceding character is the
        # escape character:
        for index in indices:
            if index == 0:
                commandAsList[index] = replacementAtBeginning
            elif commandAsList[index-1] != MapConstants.escape_char:
                commandAsList[index] = replacement
        # Put the pieces of the new command together:
        newCommand = ''.join(commandAsList)
        # Remove superfluous slashes and return:
        return newCommand.replace("//","/")
222839
def replace(self, text):
        """"""
        for (pattern, repl) in self.patterns:
            text = re.subn(pattern, repl, text)[0]
        return text
452018
public void replaceRight(Pattern aPattern, String aReplacement) {
        Object lastChild = this.children.get(this.children.size() - 1);
        if (lastChild instanceof SourceNode) {
            ((SourceNode) lastChild).replaceRight(aPattern, aReplacement);
        } else if (lastChild instanceof String) {
            this.children.set(this.children.size() - 1, aPattern.matcher(((String) lastChild)).replaceFirst(aReplacement));
        } else {
            this.children.add(aPattern.matcher("").replaceFirst(aReplacement));
        }
    }
804698
def replace_first(input, string, replacement = ''.freeze)
      input.to_s.sub(string.to_s, replacement.to_s)
    end
64673
public void replaceWithNewInstances(Collection<SSTableReader> toReplace, Collection<SSTableReader> replaceWith)
    {
        replaceReaders(toReplace, replaceWith, true);
    }
375634
def replace(value, arg):
    

    replacement = arg.split('|')
    try:
        return value.replace(replacement[0], replacement[1])
    except:
        return value
226332
public void replaceLines(int startLine, int endLine, List<String> replacementLines) {
    Preconditions.checkArgument(startLine <= endLine);
    List<String> originalLines = getLines();
    List<String> newLines = new ArrayList<>();
    for (int i = 0; i < originalLines.size(); i++) {
      int lineNum = i + 1;
      if (lineNum == startLine) {
        newLines.addAll(replacementLines);
      } else if (lineNum > startLine && lineNum <= endLine) {
        // Skip
      } else {
        newLines.add(originalLines.get(i));
      }
    }
    replaceLines(newLines);
  }
659439
function replaceWithPatterns( src, patterns ){
    return _.reduce(
        patterns,
        function( replacedCode, replacement, pattern ){
            return replacedCode.replace( new RegExp( pattern, "gi" ), replacement, "gi" );
        },
        src
    );
}
331729
def substitute_variables(command, level, name, value, target=None, **kwargs):
    """"""
    rule = kwargs.get('rule', {})
    rule_value = rule.get('value', '') if rule else ''
    substitutes = {
        '${level}': str(level),
        '${target}': str(target),
        '${name}': '"' + str(name) + '"',
        '${value}': str(value),
        '${limit_value}': str(rule_value),
    }

    result = command
    for pattern, value in substitutes.items():
        result = result.replace(pattern, value)

    return result
339354
protected void configureIfNecessary(AbstractCommand command) {

		Assert.notNull(command, "command");

		if (getCommandConfigurer() != null) {
			if (!command.isFaceConfigured()) {
                getCommandConfigurer().configure(command);
			}
		}

	}
797439
function attemptReplacePatterns(token, replacements, measureThreshold) {
  var replacement = null;

  for(var i = 0; i < replacements.length; i++) {
    if(!measureThreshold || measure(attemptReplace(token, replacements[i][0], '')) > measureThreshold)
      replacement = attemptReplace(token, replacements[i][0], replacements[i][1]);

    if(replacement)
      break;
  }

  return replacement;
}
535664
def remove_on_change(pattern=".*")
      pattern = (pattern.kind_of?(Regexp) ? pattern.source : pattern.to_s)
      if @listeners.has_key?(pattern)
        listener, proc = @listeners.delete(pattern)
        Klass.remove_OnKeyChange_Handler(listener.get_pointer(0))
        sleep @handler_sleep
        true
      else
        nil
      end
    end
1138978
function exc(pattern, except) {
        var name = pattern + ' ~ ' + except;
        return new Pattern(name, function (str, pos) {
            return !except.exec(str, pos) && pattern.exec(str, pos);
        });
    }
1294592
public String[] getReplacement(String text) {
        ConversionRule conversionRule;
        Pattern pattern;
        Matcher matcher;
        Iterator<ConversionRule> conversionRuleIterator = ruleSet.iterator();
        String additionalLine = null;
        while (conversionRuleIterator.hasNext()) {
            conversionRule = conversionRuleIterator.next();
            pattern = conversionRule.getPattern();
            matcher = pattern.matcher(text);
            if (matcher.find()) {
                // System.out.println("matching " + text);
                atLeastOneMatchOccured = true;
                String replacementText = conversionRule.replace(matcher);
                text = matcher.replaceAll(replacementText);
                if (conversionRule.getAdditionalLine() != null) {
                    additionalLine = conversionRule.getAdditionalLine();
                }
            }
        }

        if (additionalLine == null) {
            return new String[] { text };
        } else {
            return new String[] { text, additionalLine };
        }
    }
859344
private void replaceCommandLine(String replacement) {
		int currentCLSize = commandLineBuffer.size();
		commandLineBuffer = new ByteArrayOutputStream();
		for (int x = 0; x < replacement.length(); x++) {
			commandLineBuffer.write(replacement.charAt(x));
		}
		String replaceString = '\r' + promptStr;
		for (int x = 0; x <= currentCLSize; x++) {
			replaceString += ' ';
		}
		replaceString += '\r' + promptStr + replacement;
		ps.print(replaceString);
	}
196769
def replace(self, text, pattern=None):
        """"""
        cursor = self.textCursor()
        cursor.beginEditBlock()
        if pattern is not None:
            seltxt = to_text_string(cursor.selectedText())
        cursor.removeSelectedText()
        if pattern is not None:
            text = re.sub(to_text_string(pattern),
                          to_text_string(text), to_text_string(seltxt))
        cursor.insertText(text)
        cursor.endEditBlock()
1230701
function replace(pattern, replacement, val){
  utils.assertString(pattern, 'pattern');
  utils.assertString(replacement, 'replacement');
  utils.assertString(val, 'val');
  pattern = new RegExp(pattern.string, 'g');
  var res = val.string.replace(pattern, replacement.string);
  return val instanceof nodes.Ident
    ? new nodes.Ident(res)
    : new nodes.String(res);
}