I think that the first segment will match the first 'char'
of output and the inner segment will match any single
'char' thereafter.
In my analysis, I didn't go as far in to the critical
end as you

, but noticed that it was essentially super
fluous coding and noted to myself that it wasn't really
well done.
As an experiment I replicated the original code
using ping:
Code:
#!/usr/bin/expect
exp_internal 1
spawn ping [lindex $argv 0]
set cnt 0
expect {
-re ".*" {
incr cnt
send_user "Dumping expects buffers at $cnt \n\n"
parray expect_out
send_user "Ending segment\n\n"
expect -gl "*" {
if {$cnt < 10} {
incr cnt
send_user "Dumping expects buffers at $cnt \n\n"
parray expect_out
after 1500 ; exp_continue
}
send_user "Ending segment\n\n"
}
}
close $spawn_id ; wait
}
The OP is predictable:
spawn ping skrg
parent: waiting for sync byte
parent: telling child to go ahead
parent: now unsynchronized from child
spawn: returns {18716}
expect: does "" (spawn_id exp4) match glob pattern "*"? yes
expect: set expect_out(0,string) ""
expect: set expect_out(spawn_id) "exp4"
expect: set expect_out(buffer) ""
Dumping expects buffers at 3
expect_out(0,string) =
expect_out(buffer) =
expect_out(spawn_id) = exp4
Ending segment
expect: continuing expect
expect: does "" (spawn_id exp4) match glob pattern "*"? yes
expect: set expect_out(0,string) ""
expect: set expect_out(spawn_id) "exp4"
expect: set expect_out(buffer) ""
Dumping expects buffers at 4
expect_out(0,string) =
expect_out(buffer) =
expect_out(spawn_id) = exp4
Ending segment
etc..
However changing the inner segment to:
expect -re "(.*)\n"..yields satisfactory results:
expect: does "" (spawn_id exp4) match regular expression "(.*)\n"? no
64 bytes from 192.168.1.45: icmp_seq=13 ttl=255 time=0.592 ms
expect: does "64 bytes from 192.168.1.45: icmp_seq=13 ttl=255 time=0.592 ms\r\n" (spawn_id exp4) match regular expression "(.*)\n"? yes
expect: set expect_out(0,string) "64 bytes from 192.168.1.45: icmp_seq=13 ttl=255 time=0.592 ms\r\n"
expect: set expect_out(1,string) "64 bytes from 192.168.1.45: icmp_seq=13 ttl=255 time=0.592 ms\r"
expect: set expect_out(spawn_id) "exp4"
expect: set expect_out(buffer) "64 bytes from 192.168.1.45: icmp_seq=13 ttl=255 time=0.592 ms\r\n"
As would just cutting out the inner segment and using
a more concise pattern and exp_continue.
Seeya.