code: def _find_and_replace(text, start_string, end_string, replace_fn):
      """Remove everything found between instances of start_string and end_string.
  
      Replace each such instance with replace_fn(removed_text)
  
      e.g. _find_and_replace(u"the [[fat]] cat [[sat]]", u"[[", u"]]", lambda x: x)
        = u"the fat cat sat"
  
      Args:
        text: a unicode string
        start_string: a unicode string
        end_string: a unicode string
        replace_fn: a unary function from unicode string to unicode string
  
      Returns:
        a string
      """
      ret = ""
      current_pos = 0
      while True:
          start_pos = text.find(start_string, current_pos)
          if start_pos == -1:
              ret += text[current_pos:]
              break
          ret += text[current_pos:start_pos]
          end_pos = text.find(end_string, start_pos + len(start_string))
          if end_pos == -1:
              break
          ret += replace_fn(
              text[start_pos + len(start_string) : end_pos]
          )
          current_pos = end_pos + len(end_string)
      return ret
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import os
  import subprocess
  import numpy
  from tensor2tensor.data_generators import generator_utils
  from tensor2tensor.data_generators import problem
  from tensor2tensor.data_generators import text_encoder
  from tensor2tensor.data_generators import text_problems
  from tensor2tensor.utils import registry
  import tensorflow.compat.v1
label_desc: Use image node_id 4 for calling a global function with example usage: _find_and_replace(text, start_string, end_string, replace_fn) and returns: ret