in reply to regex help humbly sought

WOW, i'm sure i've never tried .*? in a regex, so if that was supposed to make sense, ignore me.

Why would you put this into one line if it is already split into easily manipulated parts?

You might as well just use BeginEditable and EndEditable and set a switch so that only the lines in the middle are accepted:

   #!/usr/bin/perl
use strict;

my $sw;

while (<DATA>) {
        if ($_ =~ /BeginEditable/) {$sw="on";}
        elsif ($_ =~ /EndEditable/) {$sw="off";}
        elsif ($sw eq "on") {print "$_"}
}

__DATA__
psycho
alpha                      
(!_-%BeginEditable$$)      nb. the "html" is irrelevent 
disco
mater
tangle
(^-EndEditables)
glyph


It's unclear from your question what else you wanted to do.

Replies are listed 'Best First'.
Re^2: regex help humbly sought
by mr_mischief (Monsignor) on Mar 06, 2008 at 05:45 UTC
    .*? is perfectly legitimate in a Perl regex. Search for "non-greedy" sometime.

    Your solution is great if the input actually has the tags in question conveniently on lines by themselves, but breaks otherwise. If you've ever worked with real users, you know that's unlikely unless the input was purely machine generated with that constraint in mind and never touched by the users.

Re^2: regex help humbly sought
by ikegami (Patriarch) on Mar 06, 2008 at 15:20 UTC

    WOW, i'm sure i've never tried .*? in a regex, so if that was supposed to make sense, ignore me

    This example should clearly illustrate the difference.

    $_ = '<S>abc<E> <S>def<E>'; print("Greedy:\n"); print(" $1\n") while /<S>(.*)<E>/g; print("Non-greedy:\n"); print(" $1\n") while /<S>(.*?)<E>/g;
    Greedy: abc<E> <S>def Non-greedy: abc def