Set a substitution.

        Equivalent to ``! sub`` in RiveScript code.

        :param str what: The original text to replace.
        :param str rep: The text to replace it with.
            Set this to ``None`` to delete the substitution.
547638
def set_substitution(self, what, rep):
        
        if rep is None:
            # Unset the variable.
            if what in self._subs:
                del self._subs[what]
        self._subs[what] = rep
806537
function replacer(match, file, line, col) {
		line = parseInt(line, 10);
		col = parseInt(col, 10);

		for (var i = 0; i < responses.length; i++) {
			var meta = responses[i].meta;
			var sourcemap = meta && meta.sourcemaps && meta.sourcemaps[file];

			if (!sourcemap) {
				continue;
			}

			var smc = new SourceMapConsumer(sourcemap);
			var pos = smc.originalPositionFor({ line: line, column: col });

			if (pos) {
				return pos.name + ' (' + file + ':' + pos.line + ':' + pos.column + ')';
			}
		}

		return match;
	}
898934
def set(self, repo):
        
        name = repo.name
        if name in self.__repositories \
           and self.__repositories[name].is_initialized:
            raise ValueError('Can not replace repositories that have been '
                             'initialized.')
        self.__repositories[name] = repo
999188
def _subs(self, substitutions, default, simplify):
        
        # track the new list of unchanged args or replaced args through
        # a substitution
        new_arguments = []
        changed_something = False

        # shortcut for basic logic True or False
        if self is self.TRUE or self is self.FALSE:
            return self

        # if the expression has no elements, e.g. is empty, do not apply
        # substitions
        if not self.args:
            return default

        # iterate the subexpressions: either plain symbols or a subexpressions
        for arg in self.args:
            # collect substitutions for exact matches
            # break as soon as we have a match
            for expr, substitution in substitutions.items():
                if arg == expr:
                    new_arguments.append(substitution)
                    changed_something = True
                    break

            # this will execute only if we did not break out of the
            # loop, e.g. if we did not change anything and did not
            # collect any substitutions
            else:
                # recursively call _subs on each arg to see if we get a
                # substituted arg
                new_arg = arg._subs(substitutions, default, simplify)
                if new_arg is None:
                    # if we did not collect a substitution for this arg,
                    # keep the arg as-is, it is not replaced by anything
                    new_arguments.append(arg)
                else:
                    # otherwise, we add the substitution for this arg instead
                    new_arguments.append(new_arg)
                    changed_something = True

        if not changed_something:
            return

        # here we did some substitution: we return a new expression
        # built from the new_arguments
        newexpr = self.__class__(*new_arguments)
        return newexpr.simplify() if simplify else newexpr
255956
def run(self, text):
        
        for regex in self.regexes:
            text = regex.sub(self.repl, text)
        return text
410461
def substitute_url_with_ref(self, txt):
        

        # Find links
        mi = re.finditer(r'\[([^\]]+|\[[^\]]+\])\]\(([^\)]+)\)', txt)
        if mi:
            # Iterate over match objects in iterator returned by
            # re.finditer
            for mo in mi:
                # Get components of current match: full matching text,
                # the link label, and the postfix to the base url in the
                # link url
                mtxt = mo.group(0)
                lbl = mo.group(1)
                url = mo.group(2)

                # Try to look up the current link url. Issue a warning if
                # the lookup fails, and do the substitution if it succeeds.
                try:
                    ref = self.get_sphinx_ref(url, lbl)
                except KeyError as ex:
                    print('Warning: %s' % ex.args[0])
                else:
                    txt = re.sub(re.escape(mtxt), ref, txt)

        return txt
931698
def reprcall(name, args=(), kwargs=(), keywords='', sep=', ',
        argfilter=repr):
    """"""
    if keywords:
        keywords = ((', ' if (args or kwargs) else '') +
                    '**' + keywords)
    argfilter = argfilter or repr
    return "{name}({args}{sep}{kwargs}{keywords})".format(
            name=name, args=reprargs(args, filter=argfilter),
            sep=(args and kwargs) and sep or "",
            kwargs=reprkwargs(kwargs, sep), keywords=keywords or '')
259575
function (rep, callback) {
                if (_.isFunction(config.prepare)) {
                    config.prepare(rep, wrap(callback));
                } else {
                    callback(null, rep);
                }
            }
1011580
public void repr(StringBuilder buf, String sep) {
    if (style != null) {
      buf.append("style=").append(style);
    }
    super.repr(buf, sep);
  }
258938
def remove(text, what, count=None, strip=False):
    '''
    
    '''
    return replace(text, what, '', count=count, strip=strip)
241843
def set_substitution(self, word, substitution):
        
        # Parse the word and its substitution
        raw_word = re.escape(word)
        raw_substitution = substitution

        case_word = re.escape(normalize(word, preserve_case=True))
        case_substitution = normalize(substitution, preserve_case=True)

        word = re.escape(normalize(word))
        substitution = normalize(substitution)

        # Compile and group the regular expressions
        raw_sub = (re.compile(r'\b{word}\b'.format(word=raw_word), re.IGNORECASE), raw_substitution)
        case_sub = (re.compile(r'\b{word}\b'.format(word=case_word), re.IGNORECASE), case_substitution)
        sub = (re.compile(r'\b{word}\b'.format(word=word), re.IGNORECASE), substitution)

        sub_group = (sub, case_sub, raw_sub)

        # Make sure this substitution hasn't already been processed and add it to the substitutions list
        if sub_group not in self._substitutions:
            self._log.info('Appending new word substitution: "{word}" => "{sub}"'.format(word=word, sub=substitution))
            self._substitutions.append(sub_group)
1102478
def __sub(self, string: str = '') -> str:
        
        replacer = self.random.choice(['_', '-'])
        return re.sub(r'\s+', replacer, string.strip())
375634
def replace(value, arg):
    

    replacement = arg.split('|')
    try:
        return value.replace(replacement[0], replacement[1])
    except:
        return value
1369563
def replace(self, pat, rep):
        
        check_type(pat, str)
        check_type(rep, str)

        return _series_str_result(self, weld_str_replace, pat=pat, rep=rep)
451866
public void repr(StringBuilder buf, String sep) {
    buf.append("format=").append(format);
    super.repr(buf, sep);
  }
842869
def repl(optimize=True, persist=True):
    
    print("Extra commands for the REPL:")
    print(".code    - print code")
    print(".raw     - print raw code")
    print(".quit    - exit immediately")
    print(".reset   - reset machine (IP and stacks)")
    print(".restart - create a clean, new machine")
    print(".clear   - same as .restart")
    print(".stack   - print data stack")
    print("")

    machine = Machine([])

    def match(s, *args):
        return any(map(lambda arg: s.strip()==arg, args))

    while True:
        try:
            source = raw_input("> ").strip()

            if source[0] == "." and len(source) > 1:
                if match(source, ".quit"):
                    return
                elif match(source, ".code"):
                    print_code(machine)
                elif match(source, ".raw"):
                    print(machine.code)
                elif match(source, ".reset"):
                    machine.reset()
                elif match(source, ".restart", ".clear"):
                    machine = Machine([])
                elif match(source, ".stack"):
                    print(machine.stack)
                else:
                    raise ParseError("Unknown command: %s" % source)
                continue

            code = compile(parse(source), silent=False, optimize=optimize)

            if not persist:
                machine.reset()

            machine.code += code
            machine.run()
        except EOFError:
            return
        except KeyboardInterrupt:
            return
        except ParseError as e:
            print("Parse error: %s" % e)
        except MachineError as e:
            print("Machine error: %s" % e)
        except CompileError as e:
            print("Compile error: %s" % e)
1321465
public static Expression replace(Expression expression, String substring, String repl) {
        return x("REPLACE(" + expression.toString() + ", \"" + substring + "\", \"" + repl + "\")");
    }