Thanks gryphon, not exactly what [I wanted] but that was my was'nt clear about what I wantd. I should have used an example like: '[VP This stuff is [NP the left NP] [NP other thing NP] VP]' into ("This stuff is", "[NP the left NP]", "[NP other thing NP]") Here's the code that works like a need incase someone else need to split a anchor deliminated strings(in this case the center of " [" and "] ")and ignore the nested ones.nested
#!/usr/bin/perl -w use strict; #my $input = '[VP is [NP one NP] it [NP two NP] working VP]'; my $input = '[VP This stuff is [NP the left NP] [NP other thing NP] VP +]'; #my $input = '[VP [NP This NP] [VP is [NP [NP the turning point NP] [P +P to [NP the left NP] PP] NP] VP] . VP]'; #my $input = '[S [NP This NP] [VP is [NP [NP the turning point NP] ' . + # '[PP to [NP the left NP] PP] NP] VP] . S]'; $input =~ s/^\[\w+\s*(.*?)\s*\w+\]$/$1\n/; my $bracket_count = 0; my @output; my $build_var; foreach (split(//, $input)) { if (/\[/) { if ($bracket_count == 0) {#DR $build_var =~ s/^\s*|\s*$//g;#dr push @output, $build_var if ($build_var ne '') +;#DR $build_var = '';#DR }#DR $bracket_count++; $build_var .= $_;#dr } elsif (/\]/) { $bracket_count--; $build_var .= $_;#dr if ($bracket_count == 0) {#DR $build_var =~ s/^\s*|\s*$//g;#dr push @output, $build_var if ($build_var ne '') +;#DR $build_var = '';#DR }#DR } elsif (/\n/) {#dr Should be the end $build_var =~ s/^\s*|\s*$//g;#dr push @output, $build_var if ($build_var ne '');#DR } else {#dr $build_var .= $_;#dr } } foreach (@output) { print '"', $_, '"', "\n"; }

In reply to Re: Re: Non deliminatd Nested text by Dr.Altaica
in thread Non deliminatd Nested text by Dr.Altaica

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.