Posted to tcl by mjanssen at Wed Jan 25 20:56:37 GMT 2017view raw

  1. proc matchGroup { string groups } {
  2. foreach {test exs} $groups {
  3. foreach ex $exs {
  4. if {[regexp -nocase $ex $string -> match]} {
  5. puts "Matched: $test | Regexp: $ex"
  6. return
  7. }
  8. }
  9. }
  10. }
  11.  
  12.  
  13. set groups [list test1 (first)]
  14. lappend groups test2 [list (second) (other)]]
  15. lappend groups test3 [list (final) (works) (last)]]
  16.  
  17.  
  18.  
  19. % matchGroup "this is first" $groups
  20. Matched: test1 | Regexp: (first)
  21. % matchGroup "this is the second test and i match some other words in here" $groups
  22. Matched: test2 | Regexp: (second)
  23. % matchGroup "this is the final test just hope that its works as it is the last test" $groups
  24. Matched: test3 | Regexp: (final)
  25.