12.5.27    lsearch

Description:   See if a list contains a particular element

Syntax:         lsearch ?mode? list pattern

         

Argument:     mode,  list , search pattern

Returns:         1 or 0

See Also:       lappend,  list, length, lindex

 

Examples:      #example 1

if {[lsearch $swl $v] == -1} {

                                set error "invalid config option, must be one of: $swl"

                                }      

 

This command searches the elements of list to see if one of them matches pattern. If so, the command returns the index of the first matching element. If not, the command returns -1. The mode argument indicates how the elements of the list are to be matched against pattern and it must have one of the following values:

 

-exact            The list element must contain exactly the same string as pattern.

-glob               Pattern is a glob-style pattern that is matched against each list element using the same rules as the string match command. If mode is omitted then it defaults to -glob

-regexp

Pattern is treated as a regular expression and matched against each list element using the same rules as the regexp command.

.