note
GrandFather
<p>You can't do it easily with a single regex, but you can do it with a modest amount of code:</p>
<c>
use strict;
use warnings;
while (<DATA>) {
if (m|<list>| .. m|</list>|) {
s/^(?!<list>)|(?<=<list>)/<item>/g;
s-(?=</list>)|(?<!</list>)(?=\n)-</item>-g;
}
print;
}
__DATA__
The first quick brown fox jumps over the lazy dog.
<list>The quick brown fox jumps over the lazy dog.
The quick brown fox jumps over the lazy dog.
The quick brown fox jumps over the lazy dog.</list>
The last quick brown fox jumps over the lazy dog.
</c>
<p>Prints:</p>
<c>
The first quick brown fox jumps over the lazy dog.
<list><item>The quick brown fox jumps over the lazy dog.</item>
<item>The quick brown fox jumps over the lazy dog.</item>
<item>The quick brown fox jumps over the lazy dog.</item></list>
The last quick brown fox jumps over the lazy dog.
</c>
<div class="pmsig"><div class="pmsig-461912">
<hr>DWIM is Perl's answer to Gödel
</div></div>
556880
556880