Search code examples
tcleggdrop

how to lsearch in list always match


I want match search from a list. I have dir names example:

blabla.aa
cc.oiwerwer
asfd.Dd.asoiwer

and I want to check if it is in the list (upper case should be ignored).

bind pub "-|-" !tt tt
proc tt {nick host handle channel arg} {

    set name [lindex [split $arg] 0]
    set groups {aa BB Cc DD Ee Ff gg hh}

    if {[lsearch -inline $groups $name] != -1} {
        putnow "PRIVMSG $channel :match name $name"
    }
}

No matter what I write, it always says match...

Regards


Solution

  • If I understood correctly, you want to know if any element of the list groups matches the dir name examples. If that's so, then you should use a loop with string match:

    bind pub "-|-" !tt tt
    proc tt {nick host handle channel arg} {
        set name [lindex [split $arg] 0]
        set groups {aa BB Cc DD Ee Ff gg hh}
    
        foreach group $groups {
            if {[string match -nocase *$group* $name]} {
                putnow "PRIVMSG $channel :$name matched $group"
                break
            }
        }
    }
    

    codepad test