Add in valid emojis in a string where a valid emoji is between ::
551015
def replace(cls, replacement_string):
        """"""
        e = cls()

        def _replace_emoji(match):
            val = match.group(1)
            if val in e:
                return e._image_string(match.group(1))
            else:
                return match.group(0)

        return e._pattern.sub(_replace_emoji, replacement_string)
550409
private static String processStringWithRegex(String text, Pattern pattern, int startIndex, boolean recurseEmojify) {
		//System.out.println(text);
		Matcher matcher = pattern.matcher(text);
		StringBuffer sb = new StringBuffer();
		int resetIndex = 0;
		
		if(startIndex > 0) {
			matcher.region(startIndex, text.length());
		} 
		
		while (matcher.find()) {
			
			String emojiCode = matcher.group();
			
			Emoji emoji = getEmoji(emojiCode);
			// replace matched tokens with emojis
			
			if(emoji!=null) {
				matcher.appendReplacement(sb, emoji.getEmoji());
			} else {
				if(htmlSurrogateEntityPattern2.matcher(emojiCode).matches()) {
					String highSurrogate1 = matcher.group("H1");
					String highSurrogate2 = matcher.group("H2");
					String lowSurrogate1 = matcher.group("L1");
					String lowSurrogate2 = matcher.group("L2");
					matcher.appendReplacement(sb, processStringWithRegex(highSurrogate1+highSurrogate2, shortCodeOrHtmlEntityPattern, 0, false));
					
					//basically this handles &#junk1;&#10084;&#65039;&#junk2; scenario
					//verifies if &#junk1;&#10084; or &#junk1; are valid emojis via recursion
					//if not move past &#junk1; and reset the cursor to &#10084;
					if(sb.toString().endsWith(highSurrogate2)) {
						resetIndex = sb.length() - highSurrogate2.length();
					} else {
						resetIndex = sb.length();
					}
					sb.append(lowSurrogate1);
					sb.append(lowSurrogate2);
					break;
				} else if(htmlSurrogateEntityPattern.matcher(emojiCode).matches()) {
					//could be individual html entities assumed as surrogate pair
					String highSurrogate = matcher.group("H");
					String lowSurrogate = matcher.group("L");
					matcher.appendReplacement(sb, processStringWithRegex(highSurrogate, htmlEntityPattern, 0, true));
					resetIndex = sb.length();
					sb.append(lowSurrogate);
					break;
				} else {
					matcher.appendReplacement(sb, emojiCode);
				}
			}

		}
		matcher.appendTail(sb);
		
		//do not recurse emojify when coming here through htmlSurrogateEntityPattern2..so we get a chance to check if the tail
		//is part of a surrogate entity
		if(recurseEmojify && resetIndex > 0) {
			return emojify(sb.toString(), resetIndex);
		}
		return sb.toString();
	}
1285383
def regexp_replace_emoticons(content):
    
    for emoticon, emoticon_html in EMOTICONS_COMPILED:
        if emoticon.search(content):
            content = emoticon.sub(emoticon_html, content)
    return content
1200665
def put_string(self, uri, text):
        
        self._collection[uri] = Template(
                                    text,
                                    lookup=self,
                                    uri=uri,
                                    **self.template_args)
1360995
function getPandocId (text) {
  text = text
    .replace(emojiRegex(), '') // Strip emojis
    .toLowerCase()
    .trim()
    .replace(/%25|%/ig, '')   // remove single % signs
    .replace(RE_ENTITIES, '') // remove xml/html entities
    .replace(RE_SPECIALS, '') // single chars that are removed but not [.-]
    .replace(/\s+/g, '-')     // whitespaces
    .replace(/^-+|-+$/g, '')  // heading/ tailing hyphen
    .replace(RE_CJK, '')      // CJK punctuations that are removed

  if (/^[0-9-]+$/.test(text)) {
    text = 'section'
  }
  return text
}
525637
private static String replaceInvalidChars(String substring) {
        StringBuilder builder = new StringBuilder();
        for(char c : substring.toCharArray()) {
            if(c < 32) {
                builder.append('.');
            } else {
                builder.append(c);
            }
        }
        return builder.toString();
    }
322008
def emoji_list(server, n=1):
    """"""
    global EMOJI
    if EMOJI is None:
        EMOJI = EmojiCache(server)
    return EMOJI.get(n)
626586
def validate_symbol(text):
    

    match_list = __RE_SYMBOL.findall(preprocess(text))
    if match_list:
        raise InvalidCharError("invalid symbols found: {}".format(match_list))
81340
def unify_quotes(token_string, preferred_quote):
    """"""
    bad_quote = {'"': "'",
                 "'": '"'}[preferred_quote]

    allowed_starts = {
        '': bad_quote,
        'f': 'f' + bad_quote,
        'b': 'b' + bad_quote
    }

    if not any(token_string.startswith(start)
               for start in allowed_starts.values()):
        return token_string

    if token_string.count(bad_quote) != 2:
        return token_string

    if preferred_quote in token_string:
        return token_string

    assert token_string.endswith(bad_quote)
    assert len(token_string) >= 2
    for prefix, start in allowed_starts.items():
        if token_string.startswith(start):
            chars_to_strip_from_front = len(start)
            return '{prefix}{preferred_quote}{token}{preferred_quote}'.format(
                prefix=prefix,
                preferred_quote=preferred_quote,
                token=token_string[chars_to_strip_from_front:-1]
            )
957510
def emoticons_filter(content, exclude='', autoescape=None):
    
    esc = autoescape and conditional_escape or (lambda x: x)
    content = mark_safe(replace_emoticons(esc(content), exclude))
    return content
323479
def p_text(self, text):
        ''''''
        item = text[1]
        text[0] = item if item[0] != "\n" else u""
        if len(text) > 2:
            text[0] += "\n"
804886
function addPercent(change, goodEmoji = '', badEmooji = ':small_red_triangle:') {
  const formatted = (change * 100).toFixed(2);
  if (/^-|^0(?:\.0+)$/.test(formatted)) {
    return `${formatted}% ${goodEmoji}`;
  }
  return `+${formatted}% ${badEmooji}`;
}
966957
def prettyMatcherList(things):
    """"""
    norm = []
    for x in makeSequence(things):
        if hasattr(x, 'pattern'):
            norm.append(x.pattern)
        else:
            norm.append(x)
    return "('%s')" % "', '".join(norm)
75520
private function setEmoji($emoji)
    {
        // remove the whitespace
        $emoji = trim($emoji);

        $emojiValidationRegex = '_^:[\w-+]+:$_iuS';
        if (!preg_match($emojiValidationRegex, $emoji)) {
            throw new InvalidEmojiException(
                sprintf(
                    'The emoji: "%s" is not a valid emoji.
                     An emoji should always be a string starting and ending with ":".',
                    $emoji
                ),
                400
            );
        }
        $this->emoji = $emoji;

        return $this;
    }
1180063
def add_mark_at(string, index, mark):
    
    if index == -1:
        return string
    # Python can handle the case which index is out of range of given string
    return string[:index] + add_mark_char(string[index], mark) + string[index+1:]
1347022
def bothify(self, text='## ??', letters=string.ascii_letters):
        
        return self.lexify(self.numerify(text), letters=letters)
1071509
function getGitlabId (text) {
  text = basicGithubId(text)
  text = text
    .replace(emojiRegex(), '')  // Strip emojis
    .replace(/-+/g, '-')        // duplicated hyphen
  return text
}