Details
-
New Feature
-
Status: Closed
-
Major
-
Resolution: Fixed
-
None
-
None
-
None
Description
Transform each captured group into something else:
assert "2 4 6 8" == "1 2 3 4".replaceAll("
p
")
{ it * 2 }With a new Groovy method on String:
public static String replaceAll(String self, String regex, Closure
closure) {
Matcher matcher = Pattern.compile(regex).matcher(self);
if (matcher.find()) {
matcher.reset();
StringBuffer sb = new StringBuffer();
while (matcher.find())
matcher.appendTail(sb);
return sb.toString();
} else
}