Expect : Using a variable length list containing expect regexps?

From: Bob - Andover, MA (tsreyb_at_yahoo.com)
Date: 04/29/04


Date: 29 Apr 2004 12:10:46 -0700

I'd like to create a proc which takes a list containing regular
expressions and uses those as regexps in an expect block. The list can
be of arbitrary length. I'm not sure how to accomplish this. The main
problem I see is that you need to hard-code each regexp in the expect
block, but that means I cannot pass an arbitrary length list of
regexps.

Here's my hard-coded solution (but, using this approach, how can I
handle an arbitrary length of your_regexp_LIST?) :

proc expect_these {spawn_id your_regexp_LIST} {
  expect {
    -re [lindex $your_regexp_LIST 0] {
      puts "GOT first regexp"
    }
    -re [lindex $your_regexp_LIST 1] {
      puts "GOT second regexp"
    }
  }
}

..<spawn something>..
..<send something>..

expect_these $spawn_id [list \
 "localhost" \
 "127.0.0.1" \
]



Relevant Pages

  • Re: Expect : Using a variable length list containing expect regexps?
    ... > I'd like to create a proc which takes a list containing regular ... > expressions and uses those as regexps in an expect block. ... > Here's my hard-coded solution (but, using this approach, how can I ...
    (comp.lang.tcl)
  • Re: Regular Expressions for RETURN
    ... If you actually want to search for a RETURN character, ... backslash operator is used only for special regular expression ... NOT for entering control characters in the regexps. ... expressions to replace for example two lines by one? ...
    (comp.emacs.xemacs)
  • Re: Regular Expressions for RETURN
    ... If you actually want to search for a RETURN character, ... However, the end of line is marked by ctrl-J LINEFEED, not ctrl-M ... NOT for entering control characters in the regexps. ... expressions to replace for example two lines by one? ...
    (comp.emacs.xemacs)
  • Re: Need a regex searching html code
    ... Regular expressions are simply not the right tool for the job. ... You have no possibility to determine which closing tag matches a given ... applied (not that familiar with how regexps actually work). ...
    (comp.lang.ruby)
  • Re: C# Beginings
    ... parser/scanners for that matter) like the plague, never truly mastering ... - I would trust a Sensei in RegExps creating good ones. ... If you need several expressions, RegExps are not the way to go. ... surprised by both the strange things people try to do with regex and the ...
    (microsoft.public.dotnet.languages.csharp)