Skip to Content
Exploring Expect
book

Exploring Expect

by Don Libes
December 1994
Intermediate to advanced
606 pages
16h 7m
English
O'Reilly Media, Inc.
Content preview from Exploring Expect

Tcl’s string match Command

Having matched a single line, it is no longer possible to automatically break it up into pieces stored in the array expect_out. Tcl does, however, offer a standalone version of both the regular expression and glob pattern matchers.

Glob pattern matching is explicitly done using the string match command. The command follows the format:

string match pattern string

The string replaces the implicit reference to the input buffer in an expect command. The command returns 1 if there is a match or 0 if there is no match. For example:

if [string match "f*b*" "foobar"] {
    puts "match"
} else {
    puts "no match"
}

The switch command (demonstrated on page 131) is a little more like the expect command. It supports multiple patterns and actions, but like "string match“, switch uses an explicit string. Neither switch nor "string match" support the ^ and $ anchors.

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

AI Agents in Action

AI Agents in Action

Micheal Lanham
Learning Go

Learning Go

Jon Bodner

Publisher Resources

ISBN: 9781565920903Supplemental ContentErrata Page