@SuppressWarnings("JdkObsolete")
    public static Object[] replaceAllWithRegex(
            String source, String regex, String replacement, boolean caseSensitive) {
        java.util.regex.Pattern pattern = caseSensitive ?
                java.util.regex.Pattern.compile(regex) :
                java.util.regex.Pattern.compile(regex, java.util.regex.Pattern.CASE_INSENSITIVE);
        final String replacementQuoted = Matcher.quoteReplacement(replacement);
        Matcher matcher = pattern.matcher(source);
        int totalReplaced = 0;
        // Can be replaced with StringBuilder for Java 9+
        StringBuffer result = new StringBuffer(); // NOSONAR Matcher#appendReplacement needs a StringBuffer
        while (matcher.find()) {
            matcher.appendReplacement(result, replacementQuoted);
            totalReplaced++;
        }
        matcher.appendTail(result);

        return new Object[]{
                result.toString(),
                totalReplaced
        };
    }
@Test
    public void testReplaceAllWithRegexWithSearchValueContainedInReplaceValue() {
        // Bug 61054
        assertArrayEquals(new Object[]{"abcd", 1},
                JOrphanUtils.replaceAllWithRegex("abc", "abc", "abcd", true));
    }