我有一个 xml 文件和一些替换 xml 文件的替换检查列表。如何转义正则表达式并替换该 xml 文件。只是我尝试了这个概念,但它不能完美地工作......我该怎么做?
我试过了:
输入xml:
<xml>
<p class="text">The <em type="italic">end</em> of the text</p>
<p class="text">The <bold type="strong">end of the</bold> text</p>
<p class="text">The end of <samll type="caps">the<small> text</p>
</xml>
脚本:
use strict;
open(IN, "xml_file.xml") || die "can't open $!";
my $text = join '', <IN>;
my @ar = '';
my $testing;
foreach my $t (<DATA>){
@ar = split /\t/, $t;
chomp($ar[0]);
chomp($ar[1]);
$text =~ s/$ar[0]/$ar[1]/segi;
}
print $text;
__END__
<p([^>]+)?> <line>
<small([^>]+)?> <sc$1>
<bold type=\"([^"]+)\"> <strong act=\"$1\">
<(\/)?em([^>]+)?> <$1emhasis$2>
需要输出:
<xml>
<line>The <emhasis type="italic">end</emhasis> of the text</line>
<line>The <strong act="strong">end of the</strong> text</line>
<line>The end of <sc type="caps">the<sc> text</line>
</xml>
如何将此标记正则表达式替换为清单以及如何从组模式中获取价值..