code: def get_dags(
      subdir: str | None, dag_id: str, use_regex: bool = False
  ):
      """Return DAG(s) matching a given regex or dag_id."""
      from airflow.models import DagBag
  
      if not use_regex:
          return [get_dag(subdir, dag_id)]
      dagbag = DagBag(process_subdir(subdir))
      matched_dags = [
          dag
          for dag in dagbag.dags.values()
          if re2.search(dag_id, dag.dag_id)
      ]
      if not matched_dags:
          raise AirflowException(
              f"dag_id could not be found with regex: {dag_id}. Either the dag did not exist or "
              f"it failed to parse."
          )
      return matched_dags
  
imports: from __future__ import annotations
  import functools
  import logging
  import os
  import socket
  import sys
  import threading
  import traceback
  import warnings
  from argparse import Namespace
  from datetime import datetime
  from pathlib import Path
  from typing import TYPE_CHECKING, Callable, TypeVar, cast
  import re2
  from sqlalchemy import select
  from airflow import settings
  from airflow.exceptions import AirflowException, RemovedInAirflow3Warning
  from airflow.utils import cli_action_loggers
  from airflow.utils.log.non_caching_file_handler import NonCachingFileHandler
  from airflow.utils.platform import getuser, is_terminal_support_colors
  from airflow.utils.session import NEW_SESSION, provide_session
label_desc: Use image node_id 8 for calling a global function with example usage: get_dags(subdir, dag_id, use_regex) and returns: matched_dags, list