如果测试的字符串是 a后跟 任意数量的空格(包括零),然后不跟.<@> *(?!QQQ)
<@>
QQQ
然而,如果测试的字符串是<@> QQQ
正则表达式匹配。
我不明白为什么会这样,并希望在这件事上提供任何帮助。
这是一个测试脚本
use warnings;
use strict;
my @strings = ('something <@> QQQ',
'something <@> RRR',
'something <@>QQQ' ,
'something <@>RRR' );
print "$_\n" for map {$_ . " --> " . rep($_) } (@strings);
sub rep {
my $string = shift;
$string =~ s,<@> *(?!QQQ),at w/o ,;
$string =~ s,<@> *QQQ,at w/ QQQ,;
return $string;
}
这打印
something <@> QQQ --> something at w/o QQQ
something <@> RRR --> something at w/o RRR
something <@>QQQ --> something at w/ QQQ
something <@>RRR --> something at w/o RRR
我本来希望第一行是something <@> QQQ --> something at w/ QQQ
.