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!

Get Exploring Expect now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.