Search code examples
tclglob

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 ?


Solution

  • 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