// f takes variable without $ sign. if it returns null, variable is kept sS replaceDollarVars2_dyn(S s, IF1 f) { if (f == null) ret s; ret regexpReplace(s, "\\$(\\w+)|\\$\\{(.+?)\\}", matcher -> { S var = or(matcher.group(1), matcher.group(2)); S val = f.get(var); ret val == null ? matcher.group() : str(val); }); }