class ProfileAttributesResolverImpl implements ProfileAttributesResolver {

    protected String getErrorFieldName(String templateString, String attrPlaceholder) {
        String attrLiteral = Pattern.quote(attrPlaceholder);

        Supplier<Pattern> findJsonFieldNamePattern =
                () -> Pattern.compile("(?m)\"(?<name>[\\w$]+)\"\\s*:\\s*\"([^\"]|(\\\\\"))*" + attrLiteral);
        Supplier<Pattern> findXmlFieldNamePattern =
                () -> Pattern.compile("(?s)<(?<name>[\\w.-]+)((?!<[\\w.-]+).)+" + attrLiteral);

        return Stream.of(findJsonFieldNamePattern, findXmlFieldNamePattern)
                .map(pattern -> {
                    Matcher matcher = pattern.get().matcher(templateString);
                    if (matcher.find()) {
                        return matcher.group("name");
                    } else {
                        return "";
                    }
                })
                .filter(name -> !name.isEmpty())
                .findFirst()
                .orElse("");
    }

    public  ProfileAttributesResolverImpl();

}