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:
*matches any text, also an empty one.?matches one character.[chars]matches one character of the set.a-zin a set is a range. A set with no]runs to the end of the pattern. A set has no negation:^and!are characters of the set.\xmatches the character x, so\*matches a star.
An empty PATTERN matches only an empty STRING, and * matches each string.
Arguments
| Argument | Type | Default | Description |
|---|---|---|---|
| PATTERN | glob pattern | required | The pattern. |
| STRING | string | required | The text to test. |
Options
| Option | Type | Default | Summary |
|---|---|---|---|
-nocase | flag | none | Matches 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 optionReturns
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