You can't do it easily with a single regex, but you can do it with a modest amount of code:
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.
Prints:
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.
In reply to Re: Regex to replace a particular part of content
by GrandFather
in thread Regex to replace a particular part of content
by rsriram
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |