Something about the statement of the task seems very odd to me. One way (I think the "literal" way) to interpret your description would yield a sequence like this:
0. text {scope 4 {scope 2 {scope 1} scope 2} scope 4 {scope 3} scope +4} text 1. text {scope 4 {scope 2 -change1- scope 2} scope 4 {scope 3} scope +4} text 2. text {scope 4 - - - -c h a n g e 2- - - - scope 4 {scope 3} scope +4} text 3. text {scope 4 - - - -c h a n g e 2- - - - scope 4 -change3- scope +4} text 4. text - - - - - - - - - - - - -c h a n g e 4- - - - - - - - - - - - + - text
So the question would be: why even bother with the initial nested levels, since later changes will obliterate them? If that's what is supposed to happen, it would make more sense to identify the outer-most bracketing, and apply only that single substitution. Perhaps you intended to describe something different?

(Update: I suppose that if there were interactions from one step to the next - e.g. if a substitution at step 1 either creates or eliminates a condition that affects what happens in a later stage - then it becomes a more complicated business, posing greater challenges for maintenance.)


In reply to Re: Text parsing. Processing scopes and subscopes. by graff
in thread Text parsing. Processing scopes and subscopes. by Lana

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.