code: public static String substitute(String input, List<VariableInstance> variables)
      throws MdwException {
          StringBuffer substituted = new StringBuffer(input.length());
          try {
              Matcher matcher = tokenPattern.matcher(input);
              int index = 0;
              while (matcher.find()) {
                  String match = matcher.group();
                  substituted.append(input.substring(index, matcher.start()));
                  Object value = getVariableValue(match.substring(2, match.length() - 1), variables);
                  if (value != null)
                      substituted.append(value);
                  index = matcher.end();
              }
              substituted.append(input.substring(index));
              return substituted.toString();
          }
          catch (Exception ex) {
              throw new MdwException("Error substituting expression value(s) in input: '" + input + "'", ex);
          }
      }
docs: Substitutes dynamic values for expressions in the input string.
  @param input raw input string
  @param variables variable instances to use in substitutions
  @return string with values substituted