RE: [PHP] What is wrong with this preg_match?

From: Date: Thu, 27 Oct 2011 18:52:40 +0000
Subject: RE: [PHP] What is wrong with this preg_match?
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-315453@lists.php.net to get a copy of this message
-----Original Message----- From: Paul Halliday [mailto:paul.halliday@gmail.com] Sent: Thursday, October 27, 2011 2:43 PM To: PHP-General Subject: [PHP] What is wrong with this preg_match? I have the following: if (isset($argc)) { if ($argc == 1 || $argc > 2 || !preg_match("(\d{4}-\d{2}-\d{2})", $argv[1])) { echo "\nUsage: $argv[0] <yyyy-mm-dd>\n\n"; exit; } else { $base_date = $argv[1]; } } else { $base_date = date('Y-m-d'); } When I run it: $ ./process_patches.php 201-01-01 Usage: ./process_patches.php <yyyy-mm-dd> patches@innm2 ~/Code/Oculi $ ./process_patches.php 2011-011-01 Usage: ./process_patches.php <yyyy-mm-dd> patches@innm2 ~/Code/Oculi $ ./process_patches.php 2011-01-011 Works.. What am I doing wrong? Thanks! -- Paul Halliday http://www.squertproject.org/ Paul, To me, it looks like you're just getting the next 2 digits, so 2011-01-011 is getting 2011-01-01 and truncating the last 1. If you had used (I think) "^(\d{4}-\d{2}-\d{2})$" I think that would give you what you want... (but my reg-ex is horrible) Steve

« previous php.general (#315453) next »