Perform replacements on given HTML fragment.
485785
def replace(self, html):
        """"""
        self.html = html
        text = html.text()
        positions = []

        def perform_replacement(match):
            offset = sum(positions)
            start, stop = match.start() + offset, match.end() + offset

            s = self.html[start:stop]
            if self._is_replacement_allowed(s):
                repl = match.expand(self.replacement)
                self.html[start:stop] = repl
            else:
                repl = match.group()  # no replacement takes place

            positions.append(match.end())
            return repl

        while True:
            if positions:
                text = text[positions[-1]:]

            text, n = self.pattern.subn(perform_replacement, text, count=1)
            if not n:  # all is already replaced
                break
686550
def _replace(self, data, replacements):
        
        for find, repl in replacements:
            data = data.replace(find, repl)
        return data
633770
def _process_replacements(self, html):
        

        if self.config.find_string:
            for find_pattern, replace_pattern in self.config.replace_patterns:
                html = html.replace(find_pattern, replace_pattern)

            LOGGER.info(u'Done replacements.',
                        extra={'siteconfig': self.config.host})

        return html
278239
def substitute(ctx, text, old_text, new_text, instance_num=-1):
    
    text = conversions.to_string(text, ctx)
    old_text = conversions.to_string(old_text, ctx)
    new_text = conversions.to_string(new_text, ctx)

    if instance_num < 0:
        return text.replace(old_text, new_text)
    else:
        splits = text.split(old_text)
        output = splits[0]
        instance = 1
        for split in splits[1:]:
            sep = new_text if instance == instance_num else old_text
            output += sep + split
            instance += 1
        return output
1174056
def replace_one(self, replacement):
        
        self.__bulk.add_replace(self.__selector, replacement, upsert=True,
                                collation=self.__collation)
266813
public function replace($html)
    {
        $this->setOption(self::OPTION_VALUE, $html);
        $this->setOption(self::OPTION_METHOD, 'replace');

        return $this;
    }
1256914
def substitute_values(text, values):
    """"""
    shift, final_text, shifts = 0, text, defaultdict(int)
    for value in values:
        first = value['old_span'][0] + shift
        second = value['old_span'][1] + shift
        new_s = value['new_surface']
        final_text = final_text[0:first] + new_s + final_text[second:]
        shift += len(new_s) - len(value['old_surface'])
        for char in range(first + 1, len(final_text)):
            shifts[char] = shift

    logging.debug(u'Text after numeric conversion: "%s"', final_text)

    return final_text, shifts
838794
def apply(self):
        """"""
        # In this phase, we replace the substitutions in hyperlinks
        # with the contents of the sub-nodes introduced during phase 1.
        # We also remove those temporary nodes from the tree.
        subst_re = re.compile(self.subst_pattern)

        # Apply the substitutions to hyperlink references.
        for link in self.document.traverse(nodes.reference):
            substitutions = link.get('varlinks')
            if not substitutions:
                continue

            replacer = self._replace(substitutions, link.children, 1)
            link['refuri'] = subst_re.sub(replacer, link['refuri'])
            content = subst_re.sub(replacer, link[0])
            # Cleanup the temporary nodes and recreate the node's content.
            link.clear()
            del link['varlinks']
            link.append(nodes.Text(content))

        # Do the same with hyperlink targets.
        for link in self.document.traverse(nodes.target):
            substitutions = link.get('varlinks')
            if not substitutions:
                continue

            replacer = self._replace(substitutions, link.children, 0)
            link['refuri'] = subst_re.sub(replacer, link['refuri'])
            # Cleanup the temporary nodes.
            link.clear()
            del link['varlinks']
36760
public Tuple3<ReadOnlyStyledDocument<PS, SEG, S>, RichTextChange<PS, SEG, S>, MaterializedListModification<Paragraph<PS, SEG, S>>> replace(
            Replacement<PS, SEG, S> replacement) {
        return replace(replacement.getStart(), replacement.getEnd(), replacement.getDocument());
    }
1061293
def replaceItem(self, child, href):
        """"""
        assert isinstance(child, Base), "child item must be a hypercat Catalogue or Resource"
        for i in range(len(self.items)):
            if(self.items[i].href == href):
                self.items[i] = child   # Replace existing
                return
        assert False, "No such child item to replace as "+href
1167849
def replaceNewlines(string, newlineChar):
	""""""
	if newlineChar in string:
		segments = string.split(newlineChar)
		string = ""
		for segment in segments:
			string += segment
	return string
1224444
public static function replaceFragment($uri, $newFragment = '')
    {
        if ($uri === null) {
            $uri = static::getCurrentRequestUri();
        }
        $oldFragment = parse_url($uri, PHP_URL_FRAGMENT);
        return $oldFragment
            ? str_replace('#' . $oldFragment, '#' . $newFragment, $uri)
            : ($newFragment ? $uri . '#' . $newFragment : $uri);
    }
1102737
def replace(parent, idx, value, check_value=_NO_VAL):
  """"""
  if isinstance(parent, dict):
    if idx not in parent:
      raise JSONPatchError("Item does not exist")
  elif isinstance(parent, list):
    idx = int(idx)
    if idx < 0 or idx >= len(parent):
      raise JSONPatchError("List index out of range")
  if check_value is not _NO_VAL:
    if parent[idx] != check_value:
      raise JSONPatchError("Check value did not pass")
  parent[idx] = value
672946
def getFragment(self):
        """"""
        # assert self.innerHTML
        fragment = self.fragmentClass()
        self.openElements[0].reparentChildren(fragment)
        return fragment
1232052
def find_replace(self, node):
    """"""
    if isinstance(node, nodes.reference) and 'refuri' in node:
      r = node['refuri']
      if r.endswith('.md'):
        r = r[:-3] + '.html'
        node['refuri'] = r
      else:
        match = anchor_regex.match(r)
        if match:
          node['refuri'] = '{0:s}.html#{1:s}'.format(
              match.group('uri'), match.group('anchor'))
    return node
222839
def replace(self, text):
        """"""
        for (pattern, repl) in self.patterns:
            text = re.subn(pattern, repl, text)[0]
        return text
1253036
function replaceElementTagMentions (element, selector) {
  const processor = selectorParser((selectors) => {
    let nodesToReplace = []

    /**
     * looping breaks if we replace dynamically
     * so instead collect an array of nodes to swap and do it at the end
     */
    selectors.walk((node) => {
      if (node.value === element.tag && node.type === 'tag') { nodesToReplace.push(node) }
    })

    nodesToReplace.forEach((node) => node.replaceWith(element.pseudos.root))
  })

  return processor.process(selector).result
}