Issue with pexpect match
<p>I have a <code>python-pexpect</code> code snippet something like this:</p>

<pre><code>while True:
    master.sendline("show rsu-set all")
    status=master.expect(["[sS]nmp.*[ ]*=[ ]*[0-9].*[0-9]","Savari&gt;&gt;",TIMEOUT,EOF],4)
    if status == 0:
        old_slave_ip = master.match.group().split("=")[1]
        master.sendline("config rsu-set delete "+old_slave_ip)
        master.expect("Savari&gt;&gt;")

        master.sendline("config rsu-set commit")
        master.expect("Savari&gt;&gt;")
        continue
    elif status == 1:
        break
    else:
        print "Timed out or EOF reached"
        exit_flag = 1
        exit(1)
</code></pre>

<p>Actual output from the shell:</p>

<pre><code>Savari&gt;&gt; show rsu-set all 

Mode                = master
SnmpSlaveIPAddress  = 192.168.20.204
SnmpSlaveIPAddress  = 192.168.20.210
</code></pre>

<p>Here, before configuring new <code>ip</code>s I'm trying to delete, old <code>ip</code>s. So I'm   trying to match the ip address and then send instruction to <code>delete</code> that <code>ip</code>.</p>

<p>So I'm expecting the <code>ip</code> using <code>"[sS]nmp.*[ ]*=[ ]*[0-9].*[0-9]"</code> and then extracting the <code>ip</code> using <code>split()</code> method.</p>

<p>I was expecting the <code>old_slave_ip</code> value to be <code>ip</code> address only. But it also has <code>SnmpSlaveIPAddress</code> of the next line which is causing some misbehavior.</p>

<p>The output of the script is like:</p>

<pre><code>Savari&gt;&gt; show rsu-set all

Mode                = master
SnmpSlaveIPAddress  = 192.168.20.204
SnmpSlaveIPAddress  = 192.168.20.210

Savari&gt;&gt; config rsu-set delete  192.168.20.204

Savari&gt;&gt;

Savari&gt;&gt; SnmpSlaveIPAddress
          ^Command not found

Savari&gt;&gt; config rsu-set commit

Savari&gt;&gt; show rsu-set all

Mode                = master
SnmpSlaveIPAddress  = 192.168.20.210

Savari&gt;&gt; config rsu-set delete  master

Invalid value
</code></pre>

<p>This continues in an infinite loop.</p>

<p>When there is only one <code>ip</code> address the script works fine. This is happening only when there are more than one ip in the list.</p>

<p>Please help me out to figure this.</p>

<p>Thanks in advance</p>