I'm using Expect to execute a command on a router and return the output to a file. The output is a list. At the end of the list there's a statement that reads, "Found 165 active connections" (Where "165" could be any number between 0 and 2000.) I'm familiar with using Expect to return data from a router, but I'm a noob when it comes to using regex to parse that information. In this case, I only want to return the number to a file. I figured I could do that with an expression like
(?<=Found\s)\d+
. However, this doesn't work when rolled into the Expect script. Here's what I have less the router login stuff:
set log [open "/var/tmp/file.txt" "w"]
set accum {}
expect {
-regexp {(?<=Found\s)\d+} {
set accum "${accum}$expect_out(0,string)"
exp_continue
}
}
puts $log $accum
expect "$prompt"
I'm getting: "couldn't compile regular expression pattern: quantifier operand invalid" I assume that's from the braces, but I've messed with the syntax several different ways and can't seem to nail it. Hopefully someone with more Expect/Regex experience can assist. Thanks.