Posted to tcl by kbk at Sat Feb 26 18:45:46 GMT 2011view pretty
set text {And what is your definition of "between {{ and }}" {{in {{a string}} {{like this}} one}}?} set depth 0 set index 0 set result {} while {[regexp -start $index {\{\{|\}\}|[^{}]+|\{|\}} $text match]} { puts stderr [list index $index match $match depth $depth] if {$match eq "\}\}"} { incr depth -1 } if {$depth == 0} { append result $match } if {$match eq "\{\{"} { incr depth } incr index [string length $match] } puts $result