http://www.perlmonks.org?node_id=504867


in reply to need regular expression

The following will work correctly if the year is specified as 0, 1, 11, 111, or even 1111 (ones representing any digit):

use strict; use warnings; my( @dates ) = ( '4-10-31', '14-11-31' ); foreach my $date ( @dates ) { my $string = $date; $string =~ s/^(\d+)/ my $year=2000; substr($year,4-length($1),length($1))=$1; $year/e; print $string, "\n"; }

You can even override '2000' as being the base year by including the entire four-digit year, as in "1987-10-31".


Dave