in reply to Non deliminatd Nested text

Here's a nifty function for you. It requires Perl 5.6 to run; it uses a nested regex to match nested things. The second argument to get_brackets() is the depth you want.
my $str = q{[S [NP This NP] [VP is [NP [PP to [NP the left NP] PP] NP] VP] . S +]}; my $bracket; $bracket = qr{ (?: (?> [^][]* ) | \[ (??{ $bracket }) \] )+ }x; for (get_brackets($str, 1)) { print "<$_>\n" } for (get_brackets($str, 2)) { print "<<$_>>\n" } sub get_brackets { my ($str, $depth) = @_; my @hits = $str; @hits = map m{\[($bracket)\]}g, @hits for 1 .. $depth; return map "[$_]", @hits; # put the []'s back in }

_____________________________________________________
Jeff[japhy]Pinyan: Perl, regex, and perl hacker.
s++=END;++y(;-P)}y js++=;shajsj<++y(p-q)}?print:??;