| Khaled 2005-06-10, 4:02 pm |
| 0
wong_powah@yahoo.ca wrote:
> I find it difficult to match the regular expression in the Expect
> language.
> Usually I does not match the regular expression exactly, then the
> remaining characters will appear in the next match?
> Is there tips or guides about using regular expression in the Expect
> language?
> Someone tell me always to use anchoring in my regular expression.
> i.e. use "^" at the beginning and "$" at the end of my regular
> expression.
Hello,
The best advice I can give is: get the Exploring Expect book. All the
questions you mentioned are well and thoroughly answered there.
For now, here are some quick tips:
1. The output of the spawned process is stored in Expect's internal
buffer.
2. Matching is done against what is stored in this internal buffer.
3. When you match a pattern in this internal buffer, all characters
from the beginning of the buffer upto the matched string will be
removed from the internal buffer and stored into the array element
expect_out(buffer).
4. The remaining characters after the matched string will remain in the
internal buffer and will be available for the next match.
5. The "^" and "$" anchors correspond to internal buffer contents as a
whole.
6. Using "^" means you want to match the beginning of the buffer, i.e,
either the characters first sent by the spawned process, or the
beginning of the remaining string in the buffer after a previous match.
7. Using "$" means you want to match at the end of the buffer. You need
to make sure that no further output is coming from the spawned process
at the point where expect is attempting the match. This anchor is
usually used for matching prompts.
HTH,
Khaled
|