List of utility methods to do Regex String Replace
String | replace$(String text, Map Replaces the variables present in the text and returns the result. Each key will be added to the $ prefix. return replace(text, vars, "$"); |
String | replace(CharSequence target, CharSequence replacement, String string) replace return Pattern.compile(quote(target.toString()) ).matcher(string)
.replaceAll( quoteReplacement(replacement.toString()));
|
void | replace(final String regex, final String replacement, final StringBuffer source, boolean all) replace Pattern pattern = Pattern.compile(regex); final Matcher matcher = pattern.matcher(source); if (all) { matcher.replaceAll(replacement); } else { matcher.replaceFirst(replacement); |
String | replace(final String template, final Map A generic template replace function. final StringBuilder patternDefinition = new StringBuilder(); if (prefix != null) { patternDefinition.append(createLiteralString(prefix)); patternDefinition.append("("); if (useMapForMatching) { for (final Object key : map.keySet()) { patternDefinition.append(key); ... |
String | replace(Matcher m, String rv, Object value) replace while (m.find()) { if (m.group(2) != null) { rv = rv.replace(m.group(0), String.format(m.group(2), value)); } else { rv = rv.replace(m.group(0), String.valueOf(value)); return rv; ... |
String | replace(Pattern pattern, String src, Function Replace string with pattern obtaining replacement values through handler function. StringBuilder sb = null; Matcher matcher = pattern.matcher(src); int pos = 0; while (matcher.find()) { if (sb == null) { sb = new StringBuilder(); String expr = matcher.group(); ... |
String | replace(String content, String name, String value) replace Pattern pattern = Pattern.compile("[{]" + name + "[}]"); Matcher matcher = pattern.matcher(content); StringBuffer buf = new StringBuffer(); int curpos = 0; while (matcher.find()) { buf.append(content.substring(curpos, matcher.start())); curpos = matcher.end(); buf.append(value); ... |
String | replace(String input, Pattern pattern, Function replace StringBuffer sb = new StringBuffer(); Matcher m = pattern.matcher(input); while (m.find()) { m.appendReplacement(sb, replacementGenerator.apply(m)); m.appendTail(sb); return sb.toString(); |
String | replace(String input, Pattern regex, Function Finds and replaces matches from the input string using the regex regular expression and the converter replacement function. Matcher matcher = regex.matcher(input); StringBuilder sb = new StringBuilder(); int lastPosition = 0; while (matcher.find()) { sb.append(input.substring(lastPosition, matcher.start())); sb.append(converter.apply(matcher.group())); lastPosition = matcher.end(); sb.append(input.substring(lastPosition)); return sb.toString(); |
String | replace(String inputStr, String patternStr, String replacementStr) replace Pattern pattern = Pattern.compile(patternStr);
Matcher matcher = pattern.matcher(inputStr);
String output = matcher.replaceAll(replacementStr);
return output;
|