Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

What is the purpose for the regexp -inline flag

3 views
Skip to first unread message

parag...@hotmail.com

unread,
Sep 5, 2007, 2:58:35 PM9/5/07
to
I could only find usage for regexp -indices and regexp -nocase
What is the use for the regexp -inline
-Parag

Bruce

unread,
Sep 5, 2007, 3:06:31 PM9/5/07
to
useful for directly using the matches without storing in a variable


foreach itemThatMatched [regexp -all -inline $RE $input] {

doStuffWith $itemThatMatched

}

or getting a list of stuff

set listOfNumbers [regexp -all -inline {\d+} $input]

Bruce

Jonathan Bromley

unread,
Sep 5, 2007, 3:20:18 PM9/5/07
to

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.

Glenn Jackman

unread,
Sep 5, 2007, 3:25:18 PM9/5/07
to
At 2007-09-05 02:58PM, "parag...@hotmail.com" wrote:
> I could only find usage for regexp -indices and regexp -nocase
> What is the use for the regexp -inline

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

0 new messages