----- Original Message ----- From: "Owen" <rc...@pcug.org.au>
Newsgroups: perl.beginners

Hello Owen



To check the date passed with a script, I first check that the date
is in the format 20dddddd (20 followed by 6 digits exactly)

But the regex is wrong, tried /^20\d{6}/,/^20\d{6,6}?/,/^20\d{6,}?/ and
while a 7 or lesser digit number fails, eg 2009101, a 9 digit number,
like 200910103 does not fail.



unless ( $ARGV[2] =~ /^20\d{6}?/ ) { print



unless ( $ARGV[2] =~ /^20\d{6}$/) ...

If the end of line anchor is used, '$', the regex will accept an 8 digit number if it's the only entry in $ARGV[2]

Chris

"$ARGV[2]\tdate format is YYYYMMDD, eg 20091031\n"; }


How do I get the regex to fail a 9 digit number


I suppose as a work around, I could say;

unless ((length($ARGV[2]) == 8) and ( $ARGV[2] =~ /^20/){fail}

TIA


Owen


--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to