code: def extract_metadata(pattern, text):
      """Return a dictionary of metadata extracted from the text
  
      pattern - a regexp that specifies how to find
                metadata in a string. Each token has the form:
                "\(?<METADATA_TAG>...match-exp...\)" (matlab-style) or
                "\(?P<METADATA_TAG>...match-exp...\)" (Python-style)
      text - text to be searched
  
      We do a little fixup in here to change Matlab searches to Python ones
      before executing.
      """
      # Convert Matlab to Python
      orig_pattern = pattern
      pattern = re.sub("(\\(\\?)([<].+?[>])", "\\1P\\2", pattern)
      match = re.search(pattern, text)
      if match:
          return match.groupdict()
      else:
          raise ValueError(
              "Metadata extraction failed: regexp '%s' does not match '%s'"
              % (orig_pattern, text)
          )
  
file_path: CellProfiler/src/subpackages/core/cellprofiler_core/utilities/measurement.py
imports: import os
  import re
  import sys
  import tempfile
  from .hdf5_dict import get_top_level_group
  from .hdf5_dict import VERSION
label_desc: Use image node_id 6 for calling a global function with example usage: extract_metadata(pattern, text) and returns: match