@Override
        public @NonNull String formatCaption(
                final @NonNull Caption captionKey,
                final @NonNull C recipient,
                final @NonNull String caption,
                final @NonNull List<@NonNull CaptionVariable> variables
        ) {
            final Map<String, String> replacements = new HashMap<>();
            for (final CaptionVariable variable : variables) {
                replacements.put(variable.key(), variable.value());
            }

            final Matcher matcher = this.pattern.matcher(caption);
            final StringBuffer stringBuffer = new StringBuffer();
            while (matcher.find()) {
                final String replacement = replacements.get(matcher.group(1));
                matcher.appendReplacement(stringBuffer, replacement == null ? "$0" : replacement);
            }
            matcher.appendTail(stringBuffer);

            return stringBuffer.toString();
        }
Formats the {@code caption}.

@param captionKey the caption key
@param recipient  the recipient of the message
@param caption    the value of the caption
@param variables  the caption variables
@return the transformed message
cloud-core/src/main/java/org/incendo/cloud/caption/CaptionFormatter.java