本文介绍了Perl正则表达式在相同情况下替换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果您有一个简单的正则表达式,请按如下所示替换perl:
If you have a simple regex replace in perl as follows:
($line =~ s/JAM/AAA/g){
我将如何对其进行修改,以使其看起来像匹配项,并使替换项与匹配项相同,例如:
how would I modify it so that it looks at the match and makes the replacement the same case as the match for example:
"JAM"将变为"AAA"而"jam"将变成"aaa"
'JAM' would become 'AAA'and 'jam' would become 'aaa'
推荐答案
$line =~ s/JAM/{$& eq 'jam' ? 'aaa' : 'AAA'}/gie;
这篇关于Perl正则表达式在相同情况下替换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!