code: def wait_for_string(self, expected_string, timeout=60):
          
          #                    0                         1                        2                        3
          events = [self.syntax_error_re, self.connection_closed_re, expected_string, self.press_return_re,
                    #        4           5                 6                7
                    self.more_re, pexpect.TIMEOUT, pexpect.EOF, self.buffer_overflow_re]
  
          # add detected prompts chain
          events += self.device.get_previous_prompts()  # without target prompt
  
          self.log("Expecting: {}".format(pattern_to_str(expected_string)))
  
          transitions = [
              (self.syntax_error_re, [0], -1, CommandSyntaxError("Command unknown", self.device.hostname), 0),
              (self.connection_closed_re, [0], 1, a_connection_closed, 10),
              (pexpect.TIMEOUT, [0], -1, CommandTimeoutError("Timeout waiting for prompt", self.device.hostname), 0),
              (pexpect.EOF, [0, 1], -1, ConnectionError("Unexpected device disconnect", self.device.hostname), 0),
              (self.more_re, [0], 0, partial(a_send, " "), 10),
              (expected_string, [0, 1], -1, a_expected_prompt, 0),
              (self.press_return_re, [0], -1, a_stays_connected, 0),
              # TODO: Customize in XR driver
              (self.buffer_overflow_re, [0], -1, CommandSyntaxError("Command too long", self.device.hostname), 0)
          ]
  
          for prompt in self.device.get_previous_prompts():
              transitions.append((prompt, [0, 1], 0, a_unexpected_prompt, 0))
  
          fsm = FSM("WAIT-4-STRING", self.device, events, transitions, timeout=timeout)
          return fsm.run()
docs: Wait for string FSM.