docs: def glob_to_path_regex(glob):
      '''Supports * and **. Backslashes can escape stars or other backslashes. As
      in pathlib, ** may not adjoin any characters other than slash. Unlike
      pathlib, because we're not talking to the actual filesystem, ** will match
      files as well as directories. Paths get canonicalized before they're
      converted, so duplicate and trailing slashes get dropped. You should make
      sure the other paths you try to match are in canonical (Posix) form as
      well.'''
  
      canonical_glob = str(PurePosixPath(glob))
  
      # The final regex starts with ^ and ends with $ to force it to match the
      # whole path.
      regex = '^'
      components = canonical_glob.split('/')
      for i, component in enumerate(components):
          if component == '**':
              if i == len(components) - 1:
                  raise GlobError(glob,
                                  '** may not be the last component in a path.')
              else:
                  regex += r'(?:[^/]+/)*'
          elif '**' in component:
              raise GlobError(glob, '** must be an entire path component.')
          else:
              if component == '*':
                  # A lone * may not match empty.
                  regex += r'[^/]+'
              else:
                  # A * with other characters may match empty. Escape all other
                  # regex special characters.
                  star_parts = split_on_stars_interpreting_backslashes(component)
                  escaped_parts = map(re.escape, star_parts)
                  regex += r'[^/]*'.join(escaped_parts)
              # Add a trailing slash for every component except **.
              if i < len(components) - 1:
                  regex += '/'
  
      regex += '$'
      return regex