[Israel.pm] RegEX Failure

Gabor Szabo szabgab at gmail.com
Fri Sep 22 07:36:31 PDT 2006


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



More information about the Perl mailing list