Posted to tcl by mjanssen at Wed Jan 25 10:52:20 GMT 2017view raw

  1. proc firstMatch { string expressions } {
  2. foreach ex $expressions {
  3. if {[regexp -nocase $ex $string -> match]} {
  4. puts "Matched: $match | Regexp: $ex"
  5. return
  6. }
  7. }
  8. }
  9.  
  10. set test(1) "this is first"
  11. set test(2) "this is the second test and i match some other words in here"
  12. set test(3) "this is the final test just hope that its works as it is the last test"
  13.  
  14. firstMatch $test(1) [list (first)]
  15. firstMatch $test(2) [list (second) (other)]
  16. firstMatch $test(3) [list (final) (works) (last)]