PDA

View Full Version : Regular expression on date


tom123
08-11-2006, 10:59 AM
I have a date, and am trying to extract the year with a regular expression.
Following code won't work.

The date format:
01-JAN-2006::00:00:00

# Get the start year.
my $date_s = $product[5];
if ($date_s =~ /.{8}(\d\d\d\d)/){
my $date_start = "$1";
}

Please help!

nkrgupta
08-11-2006, 02:20 PM
# Get the start year.
my $date_s = $product[5];
if ($date_s =~ /.{7}(\d\d\d\d)/){
my $date_start = "$1";
}

Replace the '8' by '7'

KevinADC
08-11-2006, 06:48 PM
besides the 7 instead of 8, you may have created a problem if that is the real code, because $date_start is scoped to only the "if" block:


if ($date_s =~ /.{7}(\d\d\d\d)/){
my $date_start = "$1";
}