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

  1. set haystack "here we go: test1 | test2 | test3 | test4"
  2. set i 0
  3. while {[regexp -indices -start $i -- {(\S+)( \| |$)} $haystack -> word sep]} {
  4. lassign $word start end
  5. puts [string range $haystack $start $end]
  6. lassign $sep start end
  7. if {$end < $start} break
  8. set i $end
  9. }
  10.  
  11.