int (char @NotNull [] buffer, @NotNull String pattern, int maxIndex) { char[] chars = pattern.toCharArray(); int end = buffer.length - chars.length; if (maxIndex > end) { maxIndex = end; } SearchLoop: for (int i = maxIndex; i >= 0; i--) { for (int j = 0; j < chars.length; j++) { if (chars[j] != buffer[i + j]) continue SearchLoop; } return i; } return -1; }