Posted to tcl by mjanssen at Wed Jan 25 20:56:37 GMT 2017view raw
- proc matchGroup { string groups } {
- foreach {test exs} $groups {
- foreach ex $exs {
- if {[regexp -nocase $ex $string -> match]} {
- puts "Matched: $test | Regexp: $ex"
- return
- }
- }
- }
- }
- set groups [list test1 (first)]
- lappend groups test2 [list (second) (other)]]
- lappend groups test3 [list (final) (works) (last)]]
- % matchGroup "this is first" $groups
- Matched: test1 | Regexp: (first)
- % matchGroup "this is the second test and i match some other words in here" $groups
- Matched: test2 | Regexp: (second)
- % matchGroup "this is the final test just hope that its works as it is the last test" $groups
- Matched: test3 | Regexp: (final)