private List<Object> filterAndMapAttributeValuesByPattern(final Set<Object> attributeValues, final Pattern pattern, final String returnValue) {
        val values = new ArrayList<>(attributeValues.size());
        attributeValues.forEach(v -> {
            val matcher = pattern.matcher(v.toString());
            val matches = isCompleteMatch() ? matcher.matches() : matcher.find();
            if (matches) {
                LOGGER.debug("Found a successful match for [{}] while filtering attribute values with [{}]", v, pattern.pattern());
                if (StringUtils.isNotBlank(returnValue)) {
                    val count = matcher.groupCount();
                    var resultValue = returnValue;
                    for (var i = 1; i <= count; i++) {
                        resultValue = resultValue.replace("$" + i, matcher.group(i));
                    }
                    LOGGER.debug("Final attribute value after template processing for return is [{}]", resultValue);
                    values.add(resultValue);
                } else {
                    values.add(v);
                }
            }
        });
        return values;
    }
This is {@link RegisteredServiceMutantRegexAttributeFilter}.

@author Misagh Moayyed
@since 5.3.0
core/cas-server-core-services-api/src/main/java/org/apereo/cas/services/support/RegisteredServiceMutantRegexAttributeFilter.java