private String digestExpressionAux(String originalExpression) {

    final String PATTERN_START = "%{";
    final String PATTERN_STOP = "}";
    final char PATTERN_DELIMITER = ':';

    while(true) {

      int PATTERN_START_INDEX = originalExpression.indexOf(PATTERN_START);
      int PATTERN_STOP_INDEX = originalExpression.indexOf(PATTERN_STOP, PATTERN_START_INDEX + PATTERN_START.length());

      // End the loop is %{ or } is not in the current line
      if (PATTERN_START_INDEX < 0 || PATTERN_STOP_INDEX < 0) {
        break;
      }

      // Grab what's inside %{ }
      String grokPattern = originalExpression.substring(PATTERN_START_INDEX + PATTERN_START.length(), PATTERN_STOP_INDEX);

      // Where is the : character
      int PATTERN_DELIMITER_INDEX = grokPattern.indexOf(PATTERN_DELIMITER);

      String regexName = grokPattern;
      String groupName = null;

      if (PATTERN_DELIMITER_INDEX >= 0) {
        regexName = grokPattern.substring(0, PATTERN_DELIMITER_INDEX);
        groupName = grokPattern.substring(PATTERN_DELIMITER_INDEX + 1, grokPattern.length());
      }

      final String dictionaryValue = regexDictionary.get(regexName);

      if (dictionaryValue == null) {
        throw new GrokCompilationException("Missing value for regex name : " + regexName);
      }

      // Defer till next iteration
      if (dictionaryValue.contains(PATTERN_START)) {
        break;
      }

      String replacement = dictionaryValue;

      // Named capture group
      if (null != groupName) {
        replacement = "(?<" + groupName + ">" + dictionaryValue + ")";
      }

      originalExpression = new StringBuilder(originalExpression).replace(PATTERN_START_INDEX, PATTERN_STOP_INDEX + PATTERN_STOP.length(), replacement).toString();
    }

    return originalExpression;
  }