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 に答える