At the first place I would like to clarify that the mentioned method:
public Match Expect(Regex pattern, int maximumWaitTime); is a method from the
VirtualTerminal class while the example you included uses a method from the
public string Expect(string regexPattern).
However, the behavior of both methods is the same: Receives data until the specified pattern is found, but no longer than a timeout period.
The issue in your example is caused by "incorrect" input regex pattern. Please note, that "regex:" prefix is not wanted, just pass the pattern directly.
So, your example behaves correctly: wait until pattern "regex:(.*)" is found. Because it is not found, method returns null after the specified timeout. The
m_shell.ReceivedData property contains all received data up to that time.
Also please note, that
m_shell.Expect(".*") matches everything, which is also an empty string. It leads to a specific behavior: if no data are buffered, no data are received and the method returns immediately with success. You should rather use
m_shell.Expect(".+") to receive at least one character (or more if available).
I would like to also point at the
m_shell.Match property. The idea is as follows: The
Expect method returns received data without the matched pattern. The
Match property returns a data matched by the specified pattern. The
ReceivedData property returns all received data. So, there is such an equality:
- output of the
Expect method concatenated with the
Match property is equal to the
- C#: shell.Expect("pattern") + shell.Match == shell.ReceivedData
- VB: shell.Expect("pattern") & shell.Match = shell.ReceivedData