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

Ignoring Case

The -nocase flag indicates that a match should occur as if any uppercase characters in the string were lowercase. The -nocase flag works for both regexp and expect. Like other expect flags, -nocase is applied separately to each pattern.

The -nocase flag can dramatically simplify patterns. Compare the following commands. All of them match the strings "hi there!“, "Hi there!“, "Hi There!“, and "HI THERE“, but the last command is the shortest and most readable.

expect "\[Hh]\[Ii] \[Tt]\[Hh]\[Ee]\[Rr]\[Ee]!"
expect -re "(hi there|Hi there|Hi There|HI THERE)!
expect -re "(hi|Hi|HI) (there|There|THERE)!"
expect -nocase "hi there!"

From the expect command, the -nocase flag can be used with both glob patterns and regular expressions. Non-alphabetic characters are not affected by the -nocase flag.

Do not use -nocase with uppercase characters in the pattern. Uppercase characters in the pattern can never match.

expect -nocase "HI THERE!"     ;# WRONG, CAN NEVER MATCH!
expect -nocase "hi there"      ;# RIGHT!
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