in reply to Re: Matching and replacing the minimum string from the tail of the regex
in thread Matching and replacing the minimum string from the tail of the regex
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Matching and replacing the minimum string from the tail of the regex
by abitkin (Monk) on Aug 09, 2007 at 14:13 UTC |