简体   繁体   中英

tcl list lsearch wildcard override

I have a tcl list of pairs like this; one of which has (*)star as the second element.

{ff 122} {ff 1} {fg 1} {ff *} {fg *} --->var1

now I want to search the pair {fg *} using

lsearch $var1 [list "fg" "*"]

but it wrongly shows 2 {fg 1} instead of 4 {fg *} as the * is acting as a wildcard identifier. I can not override this using /* or {*} . Can any one help me with this overriding problem.

lsearch allows you to select the algorithm used for string matching. The default is -glob which does wildcard expansion of * . But you can also chose -exact for plain string matching or -regexp for regular expressions:

lsearch -exact $var1 "fg *"

or

lsearch -regexp $var1 {fg \*}

or even

lsearch -regexp $var1 {fg\s*\*}

Depending on what you actually intend to do.

See: http://www.tcl.tk/man/tcl8.6/TclCmd/lsearch.htm

lsearch -inline -all $var1 "fg \\\*"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM