通配符在 Tcl 中是如何工作的?

How does globbing work in Tcl?

在使用 Tcl 时,如文档 here 中所述,不应该使用以下代码,

string match h* match

, return 1 用于 "match" 中匹配的 h 字符而不是实际 returns ,即 0 ?

在同一页面本身,您有以下内容,

# Matches
string match f* foo

# Matches
string match f?? foo

# Doesn't match
string match f foo

匹配是作为一个完整的单词来应用的,而不是像包含特定单词的字符串。

使用 string match h* match 时,它将尝试匹配第一个字母为 h 的模式,并进一步匹配出现零次或多次出现的任何字符串,这对于单词 [=14= 是不正确的].

相反,您可以依靠 regexp 来实现您期望的结果。

# Matches, will return 1
regexp h* match