how to match the format time

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
hhj [ So, 24 September 2006 05:16 ] [ ID #1476974 ]

Re: how to match the format time

Probably:
m{(\d+\:\d+[AaPp][mM])}igsm
?
hc.d2rk [ So, 24 September 2006 12:12 ] [ ID #1476975 ]

Re: how to match the format time

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


--
paduille.4058.mumia.w [at] earthlink.net
paduille.4058.mumia.w [ So, 24 September 2006 14:09 ] [ ID #1476976 ]

Re: how to match the format time

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
Paul Lalli [ Mo, 25 September 2006 17:43 ] [ ID #1478127 ]
Perl » alt.perl » how to match the format time

Vorheriges Thema: IIS6, Perl, & some backticks failing
Nächstes Thema: perl and xml parsing