stark
stark

Reputation: 2256

How does globbing work in Tcl?

While using Tcl, as mentioned in the documentation here, shouldn't the following code,

string match h* match

, return 1 for the matched h character in "match" instead of what it actually returns , that is, 0 ?

Upvotes: 0

Views: 747

Answers (1)

Dinesh
Dinesh

Reputation: 16428

In the same page itself you have the following content,

# Matches
string match f* foo

# Matches
string match f?? foo

# Doesn't match
string match f foo

The match is applied as if a whole word, not like string contains that particular word.

With string match h* match, it will try to match a pattern whose first letter is h and further zero or more occurrence of any string of characters, which is not true for word match.

Instead, you can rely on regexp for what you expect to happen.

# Matches, will return 1
regexp h* match

Upvotes: 2

Related Questions