how to match the format time

how to match the format time

am 24.09.2006 05:16:21 von hhj

hi guys!
i use this regular expression m/(^|\D)1?\d:[0-5]\d[ap][mM]/ig)to match
format time like12:00am 5:00pm 8:30AM, and 3:60am 99:00am 3:0pm is not
fit! it doesn't work, did anyone give a help.
m/1?\d:[0-5]\d[ap][mM]/ig can't match the data at the begin of line

Re: how to match the format time

am 24.09.2006 12:12:14 von hc.d2rk

Probably:
m{(\d+\:\d+[AaPp][mM])}igsm
?

Re: how to match the format time

am 24.09.2006 14:09:23 von paduille.4058.mumia.w

On 09/23/2006 10:16 PM, hhj wrote:
> hi guys!

Hi

> i use this regular expression m/(^|\D)1?\d:[0-5]\d[ap][mM]/ig)to match
> format time like12:00am 5:00pm 8:30AM, and 3:60am 99:00am 3:0pm is not
> fit! it doesn't work, did anyone give a help.
> m/1?\d:[0-5]\d[ap][mM]/ig can't match the data at the begin of line
>

What about this?

use strict;
use warnings;

my @strs = ('12:00am 5:00pm 8:30AM','3:60am 99:00am 3:0pm');
foreach my $str (@strs) {
my @times = $str =~ /[0-9:]+[ap]m/ig;
print join(' / ',@times), "\n";
}


--
paduille.4058.mumia.w@earthlink.net

Re: how to match the format time

am 25.09.2006 17:43:42 von Paul Lalli

hhj wrote:
> hi guys!
> i use this regular expression m/(^|\D)1?\d:[0-5]\d[ap][mM]/ig)to match
> format time like12:00am 5:00pm 8:30AM, and 3:60am 99:00am 3:0pm is not
> fit! it doesn't work, did anyone give a help.
> m/1?\d:[0-5]\d[ap][mM]/ig can't match the data at the begin of line

That wheel has already been invented:
http://search.cpan.org/~roode/Regexp-Common-time-0.01/time.p m

#!/usr/bin/perl
use strict;
use warnings;
use Regexp::Common qw/time/;

for my $time ('12:00am', '5:00pm', '8:30AM', '3:60am', '99:00am',
'3:0pm') {
print "$time ";
print $time =~ /^$RE{time}{hms}$/ ? "matches" : "doesn't match";
print "\n";
}
__END__

Output:
12:00am matches
5:00pm matches
8:30AM matches
3:60am doesn't match
99:00am doesn't match
3:0pm doesn't match

Paul Lalli