// f : Matcher -> S static S regexReplace(S s, S pat, O f) { Matcher m = Pattern.compile(pat).matcher(s); new StringBuffer buf; while (m.find()) m.appendReplacement(buf, m.quoteReplacement(str(callF(f, m)))); m.appendTail(buf); ret str(buf); }