string match

Tests whether a glob pattern matches the whole of a string.

string match ?-nocase? PATTERN STRING

Description

Gives 1 when PATTERN matches all of STRING, else 0. These characters of PATTERN have a meaning, and each other character matches itself:

An empty PATTERN matches only an empty STRING, and * matches each string.

Arguments

ArgumentTypeDefaultDescription
PATTERNglob patternrequiredThe pattern.
STRINGstringrequiredThe text to test.

Options

OptionTypeDefaultSummary
-nocaseflagnoneMatches letters with no regard to case.

-nocase

Matches letters with no regard to case.

Matches each letter of PATTERN and of STRING as lowercase, also in a set: [A-C] matches b. With two arguments in place of three, -nocase is the pattern.

% string match -nocase A* abc
1

% string match -nocase {[A-C]} b
1

# With two arguments, -nocase is the pattern and a is the string.
% string match -nocase a
0
% string match -bogus a a
bad option "-bogus": must be -nocase
-errorcode TCL LOOKUP INDEX option

Returns

1 or 0.

Examples

% string match a* abc
1

% string match {[a-c]?} bx
1

% string match {a\*} a*
1

% string match {[!a]} b
0

% string match ? ""
0

Errors

% string match a
wrong # args: should be "string match ?-nocase? pattern string"
-errorcode TCL WRONGARGS

Facts

Capability
None.
Tcl release
Tcl 9.1 and 8.6.
Since
ztcl 1.0.0-beta.1

See also