Version 0 of Find all words

Updated 2006-08-22 15:20:33 by dkf

Assuming all words are simple REs (no metacharacters):

 proc findAllWords {wordList text} {
    set start 0
    while {[llength $wordList]} {
       set RE [join $wordList |]
       if {![regexp -start $start -indices $RE $text range]} {
          return 0
       }
       set word [eval [list string range $text] $range]
       set idx [lsearch -exact $wordList $word]
       set wordList [lreplace $wordList $idx $idx]
       set start [expr {[lindex $range 1]+1}]
    }
    return 1
 }