That's what test2.tcl in this [L1 ] "Regular Expressions" [L2 ] column does.
http://zeus.itworld.com:9000/AppDev/4061/swol-1218-regex/