|
ActiveTcl User Guide |
|
Simple pattern matching - "globbing"
By default, lsearch uses the "globbing" method of finding a
match. Globbing is the wildcarding technique that most Unix shells
use.
globbing wildcards are:
- *
- Matches any quantity of any character
- ?
- Matches one occurrence of any character
- \X
- The backslash escapes a special character in globbing just the
way it does in Tcl substitutions. Using the backslash lets you use
glob to match a * or ?.
- [...]
- Matches one occurrence of any character within the brackets. A
range of characters can be matched by using a range between the
brackets. For example, [a-z] will match any lower case letter.
There is also a glob
command that
you will see in later sections that uses glob pattern matching in
directories, and returns a list of the matching files.
Example
# Matches
string match f* foo
# Matches
string match f?? foo
# Doesn't match
string match f foo
# Returns a big list of files on my Debian system.
set bins [glob /usr/bin/*]