code: def replace_bracket_expressions_in_descriptor(
      descriptor_string, prev_names=None
  ):
      fields = re.split(r"(\[|\])\s*", descriptor_string)
      out_fields = []
      i = 0
      while i < len(fields):
          f = fields[i]
          i += 1
          if f == "]":
              raise RuntimeError("Unmatched ']' in descriptor")
          elif f == "[":
              if i + 2 >= len(fields):
                  raise RuntimeError(
                      "Error tokenizing string '{0}': '[' found too close "
                      "to the end of the descriptor.".format(
                          descriptor_string
                      )
                  )
              assert isinstance(prev_names, list)
              try:
                  offset = int(fields[i])
                  assert offset < 0 and -offset <= len(prev_names)
                  i += 2  # consume the int and the ']'.
              except:
                  raise RuntimeError(
                      "Error tokenizing string '{0}': expression [{1}] has an "
                      "invalid or out of range offset.".format(
                          descriptor_string, fields[i]
                      )
                  )
              this_field = prev_names[offset]
              out_fields.append(this_field)
          else:
              out_fields.append(f)
      return "".join(out_fields)
  
imports: from __future__ import print_function
  from __future__ import division
  import re
  import sys
label_desc: Use image node_id 9 for calling a global function with example usage: replace_bracket_expressions_in_descriptor(descriptor_string, prev_names) and returns: str