foreach itemThatMatched [regexp -all -inline $RE $input] {
doStuffWith $itemThatMatched
}
or getting a list of stuff
set listOfNumbers [regexp -all -inline {\d+} $input]
Bruce
It's brilliant - especially when used with -all! You get
all the match results as a list instead of needing to
invent variable names to store them. For example, consider
your "variable_name[index1][index2]..." problem (I guess
you're looking at Verilog source code???)
proc give_me_the_arrays {Verilog} {
return [regexp -inline -all {(\w+)((?:\s*\[\d+\])+)} $Verilog]
}
[note the noncapturing ?: in the innermost parentheses]
% set stuff [give_me_the_arrays {a[3]=test[6] [9] - junk[3]}]
{a[3]} a {[3]} {test[6] [9]} test {[6] [9]} {junk[3]} junk {[3]}
Now you can scan through the list using the fancy version of
"foreach" with multiple variables, so that it picks up the
list elements in groups of three:
foreach {complete_match variable subs} $stuff {
puts "variable name = $variable, subscripts = $subs"
}
--
Jonathan Bromley, Consultant
DOULOS - Developing Design Know-how
VHDL * Verilog * SystemC * e * Perl * Tcl/Tk * Project Services
Doulos Ltd., 22 Market Place, Ringwood, BH24 1AW, UK
jonathan...@MYCOMPANY.com
http://www.MYCOMPANY.com
The contents of this message may contain personal views which
are not the views of Doulos Ltd., unless specifically stated.
You have old documentation and/or and old version of Tcl. The -inline
option was added in Tcl 8.3:
http://www.tcl.tk/man/tcl8.3/TclCmd/regexp.htm
--
Glenn Jackman
"You can only be young once. But you can always be immature." -- Dave Barry