alternatively, if it is known that the intervening line(s)
will
never begin with some pattern:
my $starter = qr{ s }xsm; # starts with this string
my $never = qr{ s }xsm; # never starts with this string
my $ender = qr{ e [ ] p }xsm; # ends with this string
my $start_line = qr{ ^ $starter [^\n]* \n }xsm;
my $intervening_line = qr{ ^ (?! $never ) [^\n]* \n }xsm;
my $end_line = qr{ $ender \n }xsm;
my $line = do { local $/; <DATA> }; # slurp all the data
$line =~ s{ $start_line $intervening_line* $end_line }
{}gxsm;
print $line;
__DATA__
Random String
s
erartt
e p
s
foo
e f
blah blah
s
adflkja
wibble wobble
e p
End of file
output:
Random String
s
foo
e f
blah blah
End of file
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.