0

我不确定我在这里做错了什么。为什么正则表达式块不匹配并且没有发生替换。请帮忙。

#!usr/bin/perl

use strict;
use warnings;

my $x = << "END";

// @@@ START COPYRIGHT @@@
//
//        nth dimesion
//
//        Copyright 2007
//        nth dimension
//        Protected as an unpublished work.
//
//  The computer program listings, specifications and documentation 
//  herein are the property of nth dimension Company,
//  L.P., or a third party supplier and shall not be reproduced, 

END

$x=~s/\/\/\s+Copyright\s+\d{4}$/Copyright 2008/g;

print "$x\n";

打印 $x 打印相同的值。请帮忙。

4

1 回答 1

1

您需要/m正则表达式开关,它被视为$行尾(而不是字符串结尾)

$x=~s/\/\/\s+Copyright\s+\d{4}$/Copyright 2008/gm;

如果你想把号码留下的所有东西都留在原地,你可以使用\K

$x =~ s|//\s+Copyright\s+\K\d{4}$|2008|gm;
于 2014-05-10T06:43:13.577 回答