On 24.01.2009 02:00, ivowel wrote: > thank you, rob. great reference. now I know that it can be done. > alas, this doc is a little over my head. can someone who has used > this construct possibly please show me how I would try it on my simple > example? > > sample = " \caption{my table \label{table-label} example: $\sqrt{2+ > \sqrt{2}}$} more here {}" > > > accomplishing this is actually not ugly at all in perl: > > use Regexp::Common; > my $matchingarg = qr/$RE{balanced}{-parens=>'{ }'})/; > /\\caption$matchingarg/; > print "The \\caption argument is $1\n"; > > of course, perl is ugly in many other respects, but here, it does > nicely. Ugliness often means bad maintainability... I'd probably use a different approach which also works with simpler regular expressions: # untested Node = Struct.new :parent, :children current = root = Node.new nil, [] tokens = input.split(%r{([](){}])}) tokens.each do |token| case token when %r{[({]} current = Node.new current, [] when %r{[])}]} current = current.parent else current.children << token end end In other words: build a rudimentary context free parser. Depends of course on what you want to do. Cheers robert -- remember.guy do |as, often| as.you_can - without end