in reply to Regex to parse a date

What do you want to do if the pattern doesn't match?
If you don't care and just want to extract anything almost looking like a date:
$_="2003 % 05 % 1720:55:23"; s/\D+//g; ($y, $m, $d, $H, $M, $S)=unpack("a4a2a2a2a2a2", $_);
If you want to take care:
$_="2003 % 05 % 1720:55:23"; warn "wrong Date" unless ($y, $m, $d, $H, $M, $S)=~ /(\d{4})\s+%\s+([01]\d)\s+%\s+([0-3] +\d)([0-2]\d):([0-5]\d):([0-5]\d)/;

Replies are listed 'Best First'.
Re: Re: Regex to parse a date
by MD (Initiate) on May 19, 2003 at 10:14 UTC
    Thanks Skeeve :-) I'm taking the pattern from a CGI script that puts the date into the % delimeted format.

    Cheers MD

    Long Live Perl Monks!