abitkin has asked for the wisdom of the Perl Monks concerning the following question:
I want to get this:use strict; my $lines = ""; while(<DATA>) { $lines .= $_; } $lines =~ s/^s.*?e p$//msg; print $lines; __DATA__ Random String s erartt e p s foo e f blah blah s adflkja e p End of file
as the expression is non-greedy, but instead I get nothing. I realize this is because it encounters the s and matches the least to the next e p. So I can evaluate each match and deal with it there, but I was wondering if there was a better way to accomplish this. Update: fixed the data space and added more information to the testcase.Random String s foo e f blah blah End of file
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Matching and replacing the minimum string from the tail of the regex
by Joost (Canon) on Aug 08, 2007 at 21:30 UTC | |
|
Re: Matching and replacing the minimum string from the tail of the regex
by GrandFather (Saint) on Aug 08, 2007 at 21:58 UTC | |
by abitkin (Monk) on Aug 08, 2007 at 23:16 UTC | |
|
Re: Matching and replacing the minimum string from the tail of the regex
by johngg (Canon) on Aug 08, 2007 at 22:05 UTC | |
|
Re: Matching and replacing the minimum string from the tail of the regex
by Anonymous Monk on Aug 09, 2007 at 01:08 UTC | |
by Anonymous Monk on Aug 09, 2007 at 01:42 UTC | |
by abitkin (Monk) on Aug 09, 2007 at 14:13 UTC | |
|
Re: Matching and replacing the minimum string from the tail of the regex
by hv (Prior) on Aug 11, 2007 at 21:34 UTC |