code: def _find_fstring_string(endpats, fstring_stack, line, lnum, pos):
      tos = fstring_stack[-1]
      allow_multiline = tos.allow_multiline()
      if tos.is_in_format_spec():
          if allow_multiline:
              regex = fstring_format_spec_multi_line
          else:
              regex = fstring_format_spec_single_line
      else:
          if allow_multiline:
              regex = fstring_string_multi_line
          else:
              regex = fstring_string_single_line
  
      match = regex.match(line, pos)
      if match is None:
          return tos.previous_lines, pos
  
      if not tos.previous_lines:
          tos.last_string_start_pos = (lnum, pos)
  
      string = match.group(0)
      for fstring_stack_node in fstring_stack:
          end_match = endpats[fstring_stack_node.quote].match(string)
          if end_match is not None:
              string = end_match.group(0)[
                  : -len(fstring_stack_node.quote)
              ]
  
      new_pos = pos
      new_pos += len(string)
      # even if allow_multiline is False, we still need to check for trailing
      # newlines, because a single-line f-string can contain line continuations
      if string.endswith("\n") or string.endswith("\r"):
          tos.previous_lines += string
          string = ""
      else:
          string = tos.previous_lines + string
  
      return string, new_pos
  
imports: from __future__ import absolute_import
  import sys
  import re
  import itertools
  from codecs import BOM_UTF8
  from typing import NamedTuple, Tuple, Iterator, Iterable, List, Dict, Pattern, Set
  from parso.python.token import PythonTokenTypes
  from parso.utils import split_lines, PythonVersionInfo, parse_version_string
label_desc: Use image node_id 8 for calling a global function with example usage: _find_fstring_string(endpats, fstring_stack, line, lnum, pos) and returns: string,  new_pos, tos,  pos