use regular expression as an argument to perl expect

Check whether this helps.

use Expect;

my $Obj = Expect->new();

$Obj->spawn("/some/tst.bash");

$Obj->expect(undef,
    [ qr/(?:.*?Hello){2}/i, sub {
            my $Self = shift;
            print "Matched qr/.*?Hello.*?Hello/i..\n";
            exp_continue; }
    ]
);

And /some/tst.bash looks like this.

echo "Hello! This is for testing. !Hello"

Basically the regex (?:.*?Hello){2} looks for anything/nothing followed by Hello twice. So in essence the following too would have matched HelloHello

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s