:param str s: string with tabs
    :param str replace: e.g. 4 spaces
    :rtype: str
483417
def replace_tab_indent(s, replace="    "):
    
    prefix = get_indent_prefix(s)
    return prefix.replace("\t", replace) + s[len(prefix):]
350250
def nl2br(s):
    
    if not isinstance(s, basestring):
        s = str(s)
    s = re.sub(r'\r\n|\r|\n', '\n', s)
    paragraphs = re.split('\n{2,}', s)
    paragraphs = ['<p>%s</p>' % p.strip().replace('\n', '<br />') for p in paragraphs]
    return '\n\n'.join(paragraphs)
380654
def strip_punctuation_space(value):
    ""
    def strip_punctuation(string):
        replacement_list = (
            (' .',  '.'),
            (' :',  ':'),
            ('( ',  '('),
            (' )',  ')'),
        )
        for match, replacement in replacement_list:
            string = string.replace(match, replacement)
        return string
    if value == None:
        return None
    if type(value) == list:
        return [strip_punctuation(v) for v in value]
    return strip_punctuation(value)
544413
def re_tab(s):
    """"""
    l = []
    p = 0
    for i in range(8, len(s), 8):
        if s[i - 2:i] == "  ":
            # collapse two or more spaces into a tab
            l.append(s[p:i].rstrip() + "\t")
            p = i

    if p == 0:
        return s
    else:
        l.append(s[p:])
        return "".join(l)
1294766
def escape_b(s, quote=True):
    ''''''
    s = s.replace(b"&", b"&amp;") # Must be done first!
    s = s.replace(b"<", b"&lt;")
    s = s.replace(b">", b"&gt;")
    if quote:
        s = s.replace(b'"', b"&quot;")
    return s
1102478
def __sub(self, string: str = '') -> str:
        
        replacer = self.random.choice(['_', '-'])
        return re.sub(r'\s+', replacer, string.strip())
47173
def replace_simple_tags(s, from_tag='italic', to_tag='i', to_open_tag=None):
    
    if to_open_tag:
        s = s.replace('<' + from_tag + '>', to_open_tag)
    elif to_tag:
        s = s.replace('<' + from_tag + '>', '<' + to_tag + '>')
        s = s.replace('<' + from_tag + '/>', '<' + to_tag + '/>')
    else:
        s = s.replace('<' + from_tag + '>', '')
        s = s.replace('<' + from_tag + '/>', '')

    if to_tag:
        s = s.replace('</' + from_tag + '>', '</' + to_tag + '>')
    else:
        s = s.replace('</' + from_tag + '>', '')

    return s
360839
def replace_each(text, items, count=None, strip=False):
    '''
    
    '''
    for a,b in items:
        text = replace(text, a, b, count=count, strip=strip)
    return text
10374
def substitute(search, replace, text):
    ''
    return re.sub(re.compile(str(search)), replace, text)
299825
def escape_tabs_newlines(s: str) -> str:
    
    if not s:
        return s
    s = s.replace("\\", r"\\")  # replace \ with \\
    s = s.replace("\n", r"\n")  # escape \n; note ord("\n") == 10
    s = s.replace("\r", r"\r")  # escape \r; note ord("\r") == 13
    s = s.replace("\t", r"\t")  # escape \t; note ord("\t") == 9
    return s
1113365
public static function replaceSuffix(string $s, string $search, string $replacement = ''): string
	{
		if (substr($s, -strlen($search)) === $search) {
			$s = substr($s, 0, -strlen($search)) . $replacement;
		}

		return $s;
	}
695415
function strip_whitespace (s) {
      if (options.strip_whitespace) {
        return s.replace(/\s*\n/g,"\n").replace(/(\r?\n){2,}/g,"\n\n");
      }
      return s;
    }
31296
public void replace (String... replace)
    {
        HashSet<String> toAdd = Sets.newHashSet();
        Iterator<String> i = _imports.iterator();
        while (i.hasNext()) {
            String name = i.next();
            for (int j = 0; j < replace.length; j += 2) {
                if (name.equals(replace[j])) {
                    toAdd.add(replace[j + 1]);
                    i.remove();
                    break;
                }
            }
        }
        _imports.addAll(toAdd);
    }
599062
function format (str, tokens) {
  for (let i = 0; i < tokens.length; i++) {
    str = str.replace(tokens[i].token, tokens[i].replacement)
  }
  return str
}
665016
def normalize(s, replace_spaces=True):
    
    whitelist = (' -' + string.ascii_letters + string.digits)

    if type(s) == six.binary_type:
        s = six.text_type(s, 'utf-8', 'ignore')

    table = {}
    for ch in [ch for ch in s if ch not in whitelist]:
        if ch not in table:
            try:
                replacement = unicodedata.normalize('NFKD', ch)[0]
                if replacement in whitelist:
                    table[ord(ch)] = replacement
                else:
                    table[ord(ch)] = u'_'
            except:
                table[ord(ch)] = u'_'

    if replace_spaces:
        return s.translate(table).replace(u'_', u'').replace(' ', '_')
    else:
        return s.translate(table).replace(u'_', u'')
1126269
function format(str, swaps) {
  // First replace the %S strings
  var index = 0;
  str = str.replace(/%S/g, function() {
    return swaps[index++];
  });
  // Then %n$S style strings
  str = str.replace(/%([0-9])\$S/g, function(match, idx) {
    return swaps[idx - 1];
  });
  return str;
}
463155
function(str) {
    return trim(str).replace(/([\r\n\s　])+/g, function(match, whitespace) {
      return whitespace === '　' ? whitespace : ' ';
    });
  }