code: def patfilter(names: Iterable[str], pat: str) -> list[str]:
      """Return the subset of the list ``names`` that match
      the regular expression (pattern) ``pat``.
  
      Adapted from fnmatch module.
      """
      if pat not in _pat_cache:
          _pat_cache[pat] = re.compile(_translate_pattern(pat))
      match = _pat_cache[pat].match
      return list(filter(match, names))
  
file_path: sphinx/sphinx/util/matching.py
imports: from __future__ import annotations
  import os.path
  import re
  from typing import TYPE_CHECKING, Callable
  from sphinx.util.osutil import canon_path, path_stabilize
label_desc: Use image node_id 4 for calling a global function with example usage: patfilter(names, pat) and returns: list