Expect is such a useful tool, I am surprised that similar functionality is not found in most scripting languages.
I use the Perl Expect.pm module (https://metacpan.org/pod/release/RGIERSIG/Expect-1.15/Expect...) since I create and maintain a lot of Perl scripts. It combines the utility of expect with the power of Perl regexes.