[Israel.pm] RegEX Failure

Georges EL OJAIMI g-ojaimi at cyberia.net.lb
Fri Sep 22 08:35:17 PDT 2006


Hello,

This is a sample of valid time:

09/22/2006 17:59:18

If the user enter 60 for minutes or seconds it is wrong! and so on...

Best regards,
Georges

> 
> From: "Gabor Szabo" <szabgab at gmail.com>
> Date: 2006/09/22 Fri PM 05:36:31 EAT
> To: "Perl in Israel" <perl at perl.org.il>
> Subject: Re: [Israel.pm] RegEX Failure
> 
> On 9/22/06, Georges EL OJAIMI <g-ojaimi at cyberia.net.lb> wrote:
> > Hello,
> >
> > I have a Regular expression that check for valid date/time insertion in a database. Sometimes this code verify abnormal time entry and other time fails.
> > Can you please check what is wrong in it:
> >
> > (1[0-2]|0?[1-9])[\\-\\/](0?[1-9]|[1][0-9]|3[01])[\\-\\/]((19|20)\\d{2}) (0?[0-9]|[1][0-9]|[2][0-3]):(0?[0-9]|[1-5][0-9]):(0?[0-9]|[1-5][0-9])
> 
> It is very hard to check such a regex, especially without examples of
> input strins. Maybe you could share with us examples of strings that that
> are recognized correctly and examples that are not recognized correctly.
> 
> In any case you could start to split this up. Using /x option you can
> add spaces and
> comments.
> 
> If I am not mistaken it would be like this:
> 
> /
> (1[0-2]|0?[1-9])                          # add comments here
> [\\-\\/]
> (0?[1-9]|[1][0-9]|3[01])
> [\\-\\/]                                       # should this be [\\\/-] instead?
> ((19|20)\\d{2})                            # why double escape \\d  ?
> [ ]                                            # is this a real space?
> (0?[0-9]|[1][0-9]|[2][0-3])
> :
> (0?[0-9]|[1-5][0-9])
> :
> (0?[0-9]|[1-5][0-9])
> /x
> 
> Gabor
> _______________________________________________
> Perl mailing list
> Perl at perl.org.il
> http://perl.org.il/mailman/listinfo/perl
> 




More information about the Perl mailing list