I'm trying to use the following code to change some xml:
$xml = '<funcCall> <funcName>write</funcName> <rhsValue>crlf</rhsValue> <symConstant>loading</symConstant> <symConstant>| |</symConstant> <symConstant>lemmas</symConstant> <symConstant>| |</symConstant> <symConstant>for</symConstant> <symConstant>| |</symConstant> <variable><lx></variable> <symConstant>| |</symConstant> <symConstant>onto</symConstant> <symConstant>| |</symConstant> <variable><lms></variable> </funcCall>'; $xml =~ s& <funcCall>. <funcName>write</funcName>. <rhsValue>crlf</rhsValue> (.<(?:symConstant|variable)>[^<]*</(?:symConstant|variable)>)+ +. </funcCall> & my $text; foreach my $expr (1..$#-) { $text .= ${$expr}; } $text =~ s#<rhsValue>crlf</rhsValue>#\\n#; $text =~ s#</?symConstant>##sg; $text =~ s#</?variable>##sg; $text =~ s#.\| \|.# #sg; "<write string=\"$text\"/>"; &xse; print $xml;
I want "<write string="loading lemmas for <lx> onto <lms>"/>" but am getting "<write string=" <lms>"/>".
I don't understand why, but the @- only has one element. I know the match is fine because when I print $& I can see that the ()+ matched several items. Any suggestions?
In reply to regex replace using position loop by nglenn
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |