in reply to RegEx to filter \s not between labels

Untested, but we did this one here before, and I think this is the pattern I followed:
$_ = "your long string"; my $output = ""; while (/\G(.*?)(STARTPRESERVE.*?STOPPRESERVE)/gcs) { my ($left, $right) = ($1, $2); # I wish I could shortcut that above +:( $left =~ s/\s+/ /g; $output .= "$left$right"; } # last bit: if (/\G(.+)/gcs) { my ($left) = $1; $left =~ s/\s+/ /g; $output .= $left; }

-- Randal L. Schwartz, Perl hacker

Replies are listed 'Best First'.
•Re: •Re: RegEx to filter \s not between labels
by merlyn (Sage) on May 23, 2002 at 00:49 UTC
    And as another strategy:
    my @temp = split /(STARTPRESERVE.*?STOPPRESERVE)/; my $output = ""; while (@temp) { local $_ = shift @temp; s/\s+/ / unless @temp % 2; $output .= $_; }

    -- Randal L. Schwartz, Perl hacker