Home » , » TCL - Simple pattern matching - "globbing"

TCL - Simple pattern matching - "globbing"

Written By 1 on Monday, June 11, 2012 | 11:34 PM


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

h f?? foo

# Doesn't

string mat
c match
string match f foo


s on my Debian system.
set bins [glob /usr/bin/*]

# Returns a big list of fil

e

0 Comment:

Post a Comment