Locating a pattern within a string
Many times, you may have the need to determine if a specific pattern exists within a string. To accomplish this, Tcl provides the match
keyword. Let's look at the syntax and then I will explain the major differences and the real strength of this keyword.
The string
syntax is as follows:
string match nocase pattern string
When invoked with the match
keyword, the string
command will attempt to locate the pattern specified.
The following details the various methods in which the pattern can be passed and illustrates the special characters the pattern can store.
Special Characters |
Description |
---|---|
|
Matches any sequence within the string, including null strings. |
|
Matches any single character in the string. |
|
Matches any character in the set provided. If |
|
Matches the character specified in This avoids... |