Replaces regular expression matches in text with replacement string
@param text
@param replacement
@return
548142
public String replace(CharSequence text, CharSequence replacement)
    {
        try
        {
            if (text.length() == 0)
            {
                if (acceptEmpty)
                {
                    return "";
                }
            }
            CharArrayWriter caw = new CharArrayWriter();
            InputReader reader = Input.getInstance(text);
            ObsoleteSimpleReplacer fsp = new ObsoleteSimpleReplacer(replacement);
            replace(reader, caw, fsp);
            return caw.toString();
        }
        catch (IOException ex)
        {
            throw new IllegalArgumentException("can't happen", ex);
        }
    }
686742
public String replaceText(String originalStr, String oldStr,
            String newStr) {
        if (oldStr == null || newStr == null || oldStr.equals(newStr)) {
            return originalStr;
        }
        return originalStr.replace(oldStr, newStr);
    }
253963
private static String sanitizeText(String text) {
        if (text.indexOf('\r') >= 0) {
            text = CR.matcher(text).replaceAll("");
        }
        if (!text.isEmpty() && !text.endsWith("\n")) {
            text += "\n";
        }
        return text;
    }
1051595
private String stripLineBreaks(String text, String replacement)
   {
      if (text.indexOf('\r') != -1 || text.indexOf('\n') != -1)
      {
         StringBuilder sb = new StringBuilder(text);

         int index;

         while ((index = sb.indexOf("\r\n")) != -1)
         {
            sb.replace(index, index + 2, replacement);
         }

         while ((index = sb.indexOf("\n\r")) != -1)
         {
            sb.replace(index, index + 2, replacement);
         }

         while ((index = sb.indexOf("\r")) != -1)
         {
            sb.replace(index, index + 1, replacement);
         }

         while ((index = sb.indexOf("\n")) != -1)
         {
            sb.replace(index, index + 1, replacement);
         }

         text = sb.toString();
      }

      return (text);
   }
223613
public static String preg_replace(String regex, String replacement, String subject) {
        Pattern p = Pattern.compile(regex);
        return preg_replace(p, replacement, subject);
    }
629929
def multiple_replace(text: str, rep: Dict[str, str]) -> str:
    
    rep = dict((re.escape(k), v) for k, v in rep.items())
    pattern = re.compile("|".join(rep.keys()))
    return pattern.sub(lambda m: rep[re.escape(m.group(0))], text)
629562
public static ReplacedString replaceString(String s, String find, String replace) {
        if (replace == null) replace = "-";
        int index = -1;
        int l = find.length();
        boolean replaced = false;
        do {
            index = s.indexOf(find, index);
            if (index >= 0) {
                replaced = true;
                s = s.substring(0, index) + replace + s.substring(index + l);
            }
        } while (index >= 0);
        return new ReplacedString(s, replaced);
    }
643300
public String match(CharSequence text)
    {
        try
        {
            if (text.length() == 0)
            {
                if (acceptEmpty)
                {
                    return "";
                }
                else
                {
                    throw new SyntaxErrorException("empty string not accepted");
                }
            }
            InputReader reader = Input.getInstance(text);
            int rc = match(reader);
            if (rc == 1 && reader.read() == -1)
            {
                return reader.getString();
            }
            else
            {
                throw new SyntaxErrorException("syntax error"
                        + "\n"
                        + reader.getLineNumber() + ": " + reader.getLine()
                        + "\n"
                        + pointer(reader.getColumnNumber() + 2));
            }
        }
        catch (IOException ex)
        {
            throw new IllegalArgumentException("can't happen");
        }
    }
464093
public static String normalize( String text ) {
        CheckArg.isNotNull(text, "text");
        // This could be much more efficient.
        return NORMALIZE_PATTERN.matcher(text).replaceAll(" ").trim();
    }
1265578
def replace(self, match, content):
        
        new_string = self.replace_expression.sub(self.replace_with, match)
        logger.info('Replacing: [ %s ] --> [ %s ]', match, new_string)
        new_content = content.replace(match, new_string)
        return new_content
609430
function replace(match, text) {
        var rng = rangeFromMatch(match);

        rng.deleteContents();

        if (text.length > 0) {
          rng.insertNode(editor.dom.doc.createTextNode(text));
        }

        return rng;
      }
1120979
public static String replaceAllWithoutRegex(String text, String from, String to) {
    if (text == null) {
      return null;
    }
    int idx = 0;
    while (true) {
      idx = text.indexOf(from, idx);
      if (idx >= 0) {
        text = text.substring(0, idx) + to + text.substring(idx + from.length());

        // lets start searching after the end of the `to` to avoid possible infinite recursion
        idx += to.length();
      } else {
        break;
      }
    }
    return text;
  }
1296178
private String replaceParameters(String text) {
    	Map<String, Object> params  = bean.getParametersBean().getParamValues();
        for  (String param : params.keySet()) {
             text = StringUtil.replace(text, "\\$P\\{" + param + "\\}", StringUtil.getValueAsString(params.get(param), null));
        }
        return text;
    }
112353
public static String replaceAll(CharSequence content, Pattern pattern, String replacementTemplate) {
		if (StrUtil.isEmpty(content)) {
			return StrUtil.str(content);
		}

		final Matcher matcher = pattern.matcher(content);
		boolean result = matcher.find();
		if (result) {
			final Set<String> varNums = findAll(PatternPool.GROUP_VAR, replacementTemplate, 1, new HashSet<String>());
			final StringBuffer sb = new StringBuffer();
			do {
				String replacement = replacementTemplate;
				for (String var : varNums) {
					int group = Integer.parseInt(var);
					replacement = replacement.replace("$" + var, matcher.group(group));
				}
				matcher.appendReplacement(sb, escape(replacement));
				result = matcher.find();
			} while (result);
			matcher.appendTail(sb);
			return sb.toString();
		}
		return StrUtil.str(content);
	}
226619
public String replace(CharSequence text)
    {
        StringBuilder sb = new StringBuilder();
        replace(sb, text);
        return sb.toString();
    }
175398
public String match(String text){
		if(null == text){
			return null;
		}
		List<String> matchAll = matchAll(text, 1);
		if(CollectionUtil.isNotEmpty(matchAll)){
			return matchAll.get(0);
		}
		return null;
	}
1272761
public static void replaceWordsIgnoreCase(StringBuilder input, String[] words, String[] replaces) {
        replaceWords(input, words, replaces, true);
    }