code: public static void deletePathByRegex(FileSystem fs, final Path path, final String regex) throws IOException {
      FileStatus[] statusList = fs.listStatus(path, path1 -> path1.getName().matches(regex));
  
      for (final FileStatus oldJobFile : statusList) {
        HadoopUtils.deletePath(fs, oldJobFile.getPath(), true);
      }
    }
docs: Delete files according to the regular expression provided
  @param fs Filesystem object
  @param path base path
  @param regex regular expression to select files to delete
  @throws IOException