I'm going to echo don't. To start with, as other's have pointed out RE is the wrong tool for this job and modules such as Date::Calc are there to do it for you. But then threre's the issue of your "simple" regular expression that is broken. I'm surprised no one pointed it out...

((17((5[3-9])|([6-9]\d)))|((18|19)\d\d)|([2-9]\d\d\d))[-/.](0[1-9]|1[0 +12])[- /.](0[1-9]|[12][0-9]|3[01]) ^ unescaped / +terminates the RE if you use it in /((17...)/ but even if you encapsulate it in a variable there's still problems: #!/usr/bin/perl @sampdata = qw ( 894/7/14 1752/8/12 1753/12/24 1957/8/30 3998/4/22 9999/3/15 10000/1/1 ); $re = "((17((5[3-9])|([6-9]\d)))|((18|19)\d\d)|([2-9]\d\d\d))[-/.](0[1 +-9]|1[012])[- /.](0[1-9]| [12][0-9]|3[01])"; while (<@sampdata>) { print; print ( /$re/ ? " is " : " is not " ); print " in range 1753 to 9999\n"; } __END__ 894/7/14 is not in range 1753 to 9999 1752/8/12 is not in range 1753 to 9999 1753/12/24 is in range 1753 to 9999 1957/8/30 is not in range 1753 to 9999 3998/4/22 is not in range 1753 to 9999 9999/3/15 is not in range 1753 to 9999 10000/1/1 is not in range 1753 to 9999 So a change of ((17((5[3-9])|([6-9]\d))) to ((17((5[3-9])|(1([6-9]\d)))) Seems to be in order. Re: the two instances of [-/.], was the second one supposed to include + a space?

What seems simple today will be a headache to verify as correct in the future when you're trying to find a real bug.

Be Appropriate && Follow Your Curiosity

In reply to Re: regular expression help by mikeraz
in thread regular expression help by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.