in reply to Capturing Date/Time
You were nearly there...
/(\w{3}) (\d+), (\d{4})(?: (\d+):(\d\d) )?/
(?: ... ) are non-capturing parentheses, so they don't muck up your dollar-digit captures.
Have you considered using split instead of a regexp? In this case it leads to much easier code to maintain
my @date_parts = split m{[\s:,]+}, $date_string; if ( @date_parts == 6 ) { # date + time } elsif ( @date_parts == 3 ) { # date only } else { die "invalid date/time combo"; }
update: added split alternative
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Capturing Date/Time
by logie17 (Friar) on Aug 16, 2007 at 21:29 UTC | |
|
Re^2: Capturing Date/Time
by Nkuvu (Priest) on Aug 16, 2007 at 21:08 UTC | |
by FunkyMonk (Bishop) on Aug 16, 2007 at 23:35 UTC |