If I want to match DEF_23
using the following regexp:
expect {
-re "DEF_\[0-9]*"
set result $expect_out(1,string)
}
why does it say no such element in array
?
How does $expect_out
work, and how can I capture the DEF
using a regexp and assign it to the variable result
?
You're looking for
expect_out(0,string)
-- the array element1,string
would be populated if you had capturing parentheses in your regular expression.The expect manpage documents the use of expect_out in the documentation of the expect command:
There is an illustrative example in the manpage.
Aleksandar - it should work if you change the match to "\ndb.*$".
If you turn on exp_internal 1, you will see the buffer contains something like this: "ls -1 db*\r\ndbupgrade.log\r\n08:46:09"
So, the caret (^) will throw your pattern match off.
It seems that the above explication is not precise! Check this example:
The test result is the same when $expect_out(1,string) or $expect_out(buffer)is used. Am I missing something or this is the expected behavior?