Question

I am not sure what i am doing wrong here. Why the regex block is not matching and substitution is not happening. Please help.

#!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";

Printing $x prints the same value. Kindly help.

Was it helpful?

Solution

You need /m regex switch, which treats $ as end of line (instead of end of string)

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

And if you want to leave in place everything left from the number, you can use \K

$x =~ s|//\s+Copyright\s+\K\d{4}$|2008|gm;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top