code: public static String relativizePath(String path, boolean withIndex)
     {
  
        if (path.startsWith("/"))
           path = path.substring(1);
        if (!withIndex && path.endsWith("]"))
        {
           int index = path.lastIndexOf('[');
           return index == -1 ? path : path.substring(0, index);
        }
        return path;
     }
docs: Creates relative path from string.
  
  @param path path
  @param withIndex indicates whether we should keep the index or not
  @return relative path