簡體   English   中英

使用Regex替換或替換Perl

[英]Replacing or Substitution in Perl using Regex

我不確定在這里我在做什么錯。 為什么正則表達式塊不匹配並且替換沒有發生。 請幫忙。

#!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將打印相同的值。 請幫助。

您需要/m regex開關,它將$作為行尾(而不是字符串尾)

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

如果您想保留數字中剩余的所有內容,可以使用\\K

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM