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?
In reply to Re: regular expression help
by mikeraz
in thread regular expression help
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |