<?xml version="1.0" encoding="windows-1252"?>
<node id="631977" title="Re: Matching and replacing the minimum string from the tail of the regex" created="2007-08-11 17:34:00" updated="2007-08-11 13:34:00">
<type id="11">
note</type>
<author id="209409">
hv</author>
<data>
<field name="doctext">
&lt;p&gt;I'm not sure if there is a better way, but to me the obvious approach is to accept 'start' followed by '(not start)*' followed by 'end':&lt;/p&gt;

&lt;c&gt;my $lines = do { local $/; &lt;DATA&gt; };
$lines =~ s{
  ^ s \n                     # start line
  (?: ^ (?! s \n ) .* \n )*  # body excluding new start line
  ^ e\ p $                   # end line
}{}xmg;
print $lines;
&lt;/c&gt;

&lt;p&gt;Note that this does more work than the original failing substitution, so you can expect it to be slower.&lt;/p&gt;

&lt;p&gt;I'm assuming that the start of a test is "an 's' followed by a newline", and on that assumption being a bit stricter than your original example about matching that.&lt;/p&gt;

&lt;p&gt;Hope this helps,&lt;/p&gt;

&lt;p&gt;Hugo&lt;/p&gt;</field>
<field name="root_node">
631414</field>
<field name="parent_node">
631414</field>
</data>
</node>
