code: def _pivot_longer_names_pattern_sequence(
      df: pd.DataFrame,
      index: Union[dict, None],
      names_to: list,
      names_pattern: Union[list, tuple],
      names_transform: Union[str, Callable, dict, None],
      dropna: bool,
      sort_by_appearance: bool,
      values_to: Union[str, list, tuple],
      ignore_index: bool,
  ) -> pd.DataFrame:
      """
      This takes care of pivoting scenarios where
      names_pattern is provided, and is a list/tuple.
      """
      values_to_is_a_sequence = isinstance(values_to, (list, tuple))
      values = df.columns
  
      mapping = [
          values.str.contains(regex, na=False, regex=True)
          for regex in names_pattern
      ]
  
      values = (arr.any() for arr in mapping)
      # within each match, check the individual matches
      # and raise an error if any is False
      for position, boolean in enumerate(values):
          if not boolean.item():
              raise ValueError(
                  "No match was returned for the regex "
                  f"at position {position} -> {names_pattern[position]}."
              )
  
      if values_to_is_a_sequence:
          mapping, outcome = np.select(
              mapping, values_to, None
          ), np.select(mapping, names_to, None)
      else:
          mapping = np.select(mapping, names_to, None)
  
      # only matched columns are retained
      values = pd.notna(mapping)
      df = df.loc[:, values]
      mapping = mapping[values]
      if values_to_is_a_sequence:
          names_to = zip(names_to, values_to)
          names_to = [*chain.from_iterable(names_to)]
          if index:
              names_to = [*index] + names_to
          outcome = outcome[values]
          arr = defaultdict(list)
          for label, name in zip(outcome, df.columns):
              arr[label].append(name)
          outcome = arr.keys()
          arr = (entry for _, entry in arr.items())
          arr = zip(*zip_longest(*arr))
          arr = map(pd.Series, arr)
          outcome = dict(zip(outcome, arr))
      else:
          outcome = None
          names_to = None
  
      mapping = pd.Series(mapping)
      values, group_max = _headers_single_series(df=df, mapping=mapping)
  
      df = _final_frame_longer(
          df=df,
          reps=group_max,
          index=index,
          outcome=outcome,
          values=values,
          names_to=names_to,
          dropna=dropna,
          names_transform=names_transform,
          sort_by_appearance=sort_by_appearance,
          ignore_index=ignore_index,
      )
  
      return df
  
imports: import re
  import warnings
  from collections import defaultdict
  from itertools import chain, zip_longest
  from typing import Callable, Optional, Pattern, Union
  import numpy
  import pandas
  import pandas_flavor
  from pandas.api.types import is_categorical_dtype, is_extension_array_dtype, is_list_like
  from pandas.core.dtypes.concat import concat_compat
  from janitor.functions.utils import _computations_expand_grid, get_index_labels
  from janitor.utils import check, refactored_function
label_desc: Use image node_id 4 for calling a global function with example usage: _pivot_longer_names_pattern_sequence(df, index, names_to, names_pattern, names_transform, dropna, sort_by_appearance, values_to, ignore_index) and returns: df