public List<Replace> getRegexReplacements(Cluster cluster) {
    if (null == regexReplacements) {
      return Collections.emptyList();
    }

    List<Replace> list = new ArrayList<>();
    for (RegexReplace regexReplaceObj : regexReplacements) {
      if (StringUtils.isBlank(regexReplaceObj.key) || StringUtils.isEmpty(regexReplaceObj.find)
          || null == regexReplaceObj.replaceWith) {
        LOG.warn(String.format("Replacement %s is invalid", regexReplaceObj));
        continue;
      }

      try {
        Config config = cluster.getDesiredConfigByType(configType);

        Map<String, String> properties = config.getProperties();
        String content = properties.get(regexReplaceObj.key);

        Pattern REGEX = Pattern.compile(regexReplaceObj.find, Pattern.MULTILINE);
        Matcher patternMatchObj = REGEX.matcher(content);

        if (regexReplaceObj.matchAll) {
          while (patternMatchObj.find()) {
            regexReplaceObj.find = patternMatchObj.group();
            if (StringUtils.isNotBlank(regexReplaceObj.find)) {
              Replace rep = regexReplaceObj.copyToReplaceObject();
              list.add(rep);
            }
          }
        } else {
          // find the first literal match and create a replacement for it
          if (patternMatchObj.find() && patternMatchObj.groupCount() == 1) {
            regexReplaceObj.find = patternMatchObj.group();
            Replace rep = regexReplaceObj.copyToReplaceObject();
            list.add(rep);
          }
        }

      } catch (Exception e) {
        LOG.error(String.format(
            "There was an error while trying to execute a regex replacement for %s/%s. The regular expression was %s",
            configType, regexReplaceObj.key, regexReplaceObj.find), e);
      }
    }

    return list;
  }
Evaluates the {@link RegexReplace} instances defined for the upgrade and
converts them into distinct {@link Replace} objects. In some cases, if the
regex matches more than 1 string in the configuration, it will create
multiple {@link Replace} objects, each with their own literal string to
find/replace.

@return the replacement tokens, never {@code null}
ambari-server/src/main/java/org/apache/ambari/server/stack/upgrade/ConfigUpgradeChangeDefinition.java