On Jun 20, Willy West said:
here is the original:
<name>willy
<desc>needs to take a nap
<email>[EMAIL PROTECTED]
here is the result that I want:
<section>
<name>
willy
</name>
<desc>
needs to take a nap
</desc>
<email>
[EMAIL PROTECTED]
</email>
</section>
if i have the whole thing in one variable $data, then
$data =~ s/<(.+?)>(.*?)<(.+?)>/<$1>$2<\\$1><$3>/;
might work (untested) for the the <name> part... but i need to be able
to work with $3 as if it were $1 later on...
You want a look-ahead:
$data =~ s{
<(.+?)> # <, then one or more characters ($1), then >
(.*?) # zero or more characters ($2)
(?= <.+?> ) # look ahead for '<...>' (but don't actually match it)
}{<$1>$2</$1>}xg;
The /x modifier there allows me to embed that whitespace and comments in
the regex half of the s///, and the /g modifier means "do this globally".
--
Jeff "japhy" Pinyan % How can we ever be the sold short or
RPI Acacia Brother #734 % the cheated, we who for every service
http://japhy.perlmonk.org/ % have long ago been overpaid?
http://www.perlmonks.org/ % -- Meister Eckhart
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>