code: def _pivot_longer_names_pattern_str(
      df: pd.DataFrame,
      index: Union[dict, None],
      names_to: list,
      names_pattern: Union[str, Pattern],
      names_transform: bool,
      values_to: str,
      dropna: bool,
      sort_by_appearance: bool,
      ignore_index: bool,
  ) -> pd.DataFrame:
      """
      This takes care of pivoting scenarios where
      names_pattern is provided, and is a string/regex.
      """
      mapping = df.columns.str.extract(names_pattern, expand=True)
  
      nulls_found = mapping.isna()
  
      if nulls_found.any(axis=None):
          no_match = df.columns[nulls_found.any(axis="columns")]
          raise ValueError(
              f"Column labels {*no_match,} "
              "could not be matched with any of the groups "
              "in the provided regex. Kindly provide a regular expression "
              "(with the correct groups) that matches all labels in the columns."
          )
  
      mapping.columns = names_to
  
      if ".value" not in names_to:
          if len(names_to) == 1:
              df.columns = mapping.iloc[:, 0]
          else:
              df.columns = pd.MultiIndex.from_frame(mapping)
          return _base_melt(
              df=df,
              index=index,
              values_to=values_to,
              names_transform=names_transform,
              dropna=dropna,
              sort_by_appearance=sort_by_appearance,
              ignore_index=ignore_index,
          )
  
      return _pivot_longer_dot_value(
          df=df,
          index=index,
          sort_by_appearance=sort_by_appearance,
          ignore_index=ignore_index,
          names_to=names_to,
          dropna=dropna,
          names_transform=names_transform,
          mapping=mapping,
      )
  
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 5 for calling a global function with example usage: _pivot_longer_names_pattern_str(df, index, names_to, names_pattern, names_transform, values_to, dropna, sort_by_appearance, ignore_index) and returns: _pivot_longer_dot_value, _base_melt