Hello All,
Alright, so this is driving me absolutely insane. I can't seem to find this ANYWHERE...
I've tried every combination and synonym I can think of for this trying to search Google.
What is the Expect/Tcl equivalent to Perl and Bash's "=~" operator, (i.e. the "contains" operator).
I'm trying to do an if statements to check if a line contains a specific string, and the only operators I could find anywhere for Expect are (==, !=, <=, >=, <, >)...
Anyone have any clue if it's possible to do a pattern match in an Expect Script's if statement?
Any thoughts would be much appreciated.
Thanks in Advance,
Matt
It's not a "contains" operator, it's a regular expression operator.
I don't think TCL has an operator for it, but it does seem to have a command.
1 Like
Hey Corona, thanks for the reply.
Right, sorry didn't mean to call it the contains operator, I was just trying to simplify... Shoulda said REGEX or Pattern Matching.
But anyway, I just checked out your link and I think that may be what I need. I'll give it a try and post back if it worked.
Thanks for dulling down my frustrations a bit lol...
I couldn't find a darn thing in google for Tcl or Expect that showed anything other then an exact match in an if statement or greater/less thens...
Thanks Again,
Matt
---------- Post updated at 03:41 PM ---------- Previous update was at 03:33 PM ----------
Hey Again Corona... Victory!
Thanks that worked..!
Here's what it should look like for anyone with a similar problem:
Basically it loops through the output from the previous send command, line by line.
set myString "foo"
:....
:.....
# Loop through the previous send command's output line-by-line
foreach line [split $expect_out(buffer) "\n"] {
# If the current line contains $myString, then...
if {[regexp ".*$myString.*" $line]} {
puts "FOUND WHAT I'M LOOKING FOR!"
}
}
1 Like