# Remove empty items at the beginning and the end of a list. proc ltrim {list {emptyRegExp "^$"}} { set first [lsearch -not -regexp $list $emptyRegExp] set last [lsearch -not -regexp [lreverse $list] $emptyRegExp] return [ if {$first == -1} { list } else { lrange $list $first end-$last } ] }Use example
eltclsh > ltrim {{} {} a b c {} 1 2 {} {} {} {} {}} a b c {} 1 2 eltclsh > ltrim {{ } {} a b c { } 1 2 { } {} " \t " {} "\t\t"} {^[ \t]*$} a b c { } 1 2
See also