private static int matchPathSegments(String path, int pathOffset, String pathSegments, boolean ignoreCase) {
    // start the search past the leading slash, if one exists
    pathOffset += path.startsWith("/", pathOffset) ? 1 : 0;
    // for search purposes we strip off leading and trailing slashes from the pathSegments to search for.
    int pathSegmentsStartOffset = pathSegments.startsWith(PATH_SEPARATOR_STRING) ? 1 : 0;
    int pathSegmentsLength = Math.max(
        pathSegments.length() - pathSegmentsStartOffset - (pathSegments.endsWith(PATH_SEPARATOR_STRING) ? 1 : 0), 0);
    int nextPathSegmentOffset = -1;
    if (path.regionMatches(ignoreCase, pathOffset, pathSegments, pathSegmentsStartOffset, pathSegmentsLength)) {
      int nextCharOffset = pathOffset + pathSegmentsLength;
      // this is only a match if the end of the path was reached or the next character is a slash (starts new segment).
      if (nextCharOffset == path.length() || path.charAt(nextCharOffset) == PATH_SEPARATOR_CHAR) {
        nextPathSegmentOffset = nextCharOffset;
      }
    }
    return nextPathSegmentOffset;
  }
A helper method to search for pathSegments of a request path. This method checks if the region of {@code path} starting
at {@code pathOffset} matches the path pathSegments in {@code pathSegments}. This will only consider it a match if the
a new segment (following slash) or the end of the path immediately follows {@code pathSegments}.
@param path the path to match the pathSegments against.
@param pathOffset the start offset in {@code path} to match against.
@param pathSegments the pathSegments to search for. This method will ignore any leading or trailing slashes in this string.
@param ignoreCase if {@code true}, ignore case when comparing characters.
@return the offset of the character following {@code pathSegments} in {@code path},
        or {@code -1} if the pathSegments to search for were not found.
ambry-api/src/main/java/com/github/ambry/rest/RequestPath.java