我输入的时候替换和删除:在Perl的正则表达式相同取一些字符串
$str = 'In order to study the opportunity cost of allocating time to the less beneficial act, we need appropriate schedules of reinforcement description <?processing-instruction \value{[email protected]@%}?> list we need appropriate schedules of reinforcement';
my $get_val = ($str=~m/<\?processing\-instruction\s*\\value\{([^\}\?>]*)\}\?>/gi)[0];
print $get_val;
不过,我需要删除整个处理指令标签的同时寻找相同。这是否可能在相同的模式?
我试过这个,但没有成功。
my ($get_val) = ($str=~s/<\?processing\-instruction\s*\\value\{([^\}\?>]*)\}\?>//gi)[0];
print $get_val;
上面的输出打印'1'。如果有人能帮助解决这个问题,我们将不胜感激。
在此先感谢。
它打印$$ @@%'我。你确定你发布了你正在运行的确切代码吗? – toolic
@toolic:虽然匹配这个是成功的,但是当替换它时不会打印。 – ssr1012
perl中的替换运算符返回替换次数,与匹配运算符不同,后者返回已加工和收集的元素列表。 –