Posted to tcl by kbk at Sat Jan 21 21:30:08 GMT 2012view pretty

set haystack "here we go: test1 | test2 | test3 | test4"
set i 0
while {[regexp -indices -start $i -- {(\S+)( \| |$)} $haystack -> word sep]} {
    lassign $word start end
    puts [string range $haystack $start $end]
    lassign $sep start end
    if {$end < $start} break
    set i $end
}