Posted to tcl by evilotto at Fri Dec 03 19:45:56 GMT 2010view pretty

set match "foo,bar,baz"

set inclusion [list]
foreach term [split $match ,] {
    lappend inclusion *$term* -
}

set inclusion [lreplace $inclusion end end {return 1}]
proc matches {s} {
    switch -glob $s {*}$::inclusion default {return 0}
}
proc ckmatch {s} {
    if [matches $s] {puts "$s matches"} else {puts "$s nomatch"}
}

ckmatch "hi, foo"
ckmatch "hi, baz"
ckmatch "hi, there"