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. |
Get Tcl/Tk 8.5 Programming Cookbook 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.