[Israel.pm] RegEX Failure
Yuval Yaari
yuval at windax.com
Sat Sep 23 14:01:09 EEST 2006
Took about a second to debug using the re pragma (and strict's help,
because either I mis copy-pasted or your regex had errors in it).
my $string = '09/22/2006 17:59:18';
$string =~
m/(1[0-2]|0?[1-9])[\\\/](0?[1-9]|[12][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])/;
(You only matched days-of-the-month that begin with either 1 or 3, not 2 :))
Seriously, all you had to do is: use re 'debug'; # I prefer debugcolor
over debug, actually
And the output is pretty straightforward :-)
~Y
Georges EL OJAIMI wrote:
> 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
>>
>>
>
> _______________________________________________
> Perl mailing list
> Perl at perl.org.il
> http://perl.org.il/mailman/listinfo/perl
>
>
>
>
More information about the Perl
mailing list