@Override
  public void processArguments(String arguments) {
    arguments=arguments.trim();
    if (arguments.length() < 2) {
      throw new RuntimeException("illegal replacement expr: " + arguments + " ; expected something like /this/that/");
    }
    String sep = arguments.substring(0, 1);
    String[] parts = arguments.split(Pattern.quote(sep));
    if (parts.length != 3) {
      throw new RuntimeException(
          "unexpected replacement expr: " + arguments + " ; expected something like /this/that/");
    }
    LOG.info("Enabling replacement of: {} => {}", parts[1], parts[2]);
    replacements.put(Pattern.compile(parts[1]), parts[2]);
  }
QTest replacement directive handler

Examples:

--! qt:replace:/there/joe/
select 'hello there!
===q.out
hello joe!

standard java regex; placeholders also work:
--! qt:replace:/Hello (.*)!/$1 was here!/

first char of regex pattern is used as separator; you may choose anything else than '/'
--! qt:replace:#this#that#
itests/util/src/main/java/org/apache/hadoop/hive/ql/qoption/QTestReplaceHandler.java