Er... OK, but this looks and functions like what I had before. How do I incorporate multiple PRESERVE tags? For example, I need to s/\s+/ /g everywhere except between MARKA and MARKB, between STARTPRESERVE and STOPPRESERVE, and between YETANOTHERMARKER and YETANOTHERMARKEREND.

I can't loop through an array of regexes because they'd just cancel eachother out and do the s/\s+/ /g everywhere. I think I need a single regex, or perhaps a pulling appart of the string into an array split by the various markers, then each element analysed. What do you think is the best approach?

## START PSEUDO-CODE my $string = $big_string_from_my_original_example; my @array_of_stuff = split /\b(?:STARTPRESERVE)|(?:STOPPRESERVE)\b| \b(?:MARKA)|(?:MARKB)\b/, $string); foreach (@array_of_stuff) { if (&check_for_marker) { push @new_array, $_; next; } s/\s+/ /g; push @new_array, $_; } $string = join '', @new_array; ## END PSEUDO-CODE

Oh, and I actually do need to remove line breaks but keep the markers in place. And although it's theoretically possible, I highly doubt any markers will ever be nested. (If they are, it's due to user error.)

gryphon
code('Perl') || die;


In reply to Re: Re: RegEx filter \s ! between labels, part 2 by gryphon
in thread RegEx filter \s ! between labels, part 2 by gryphon

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.