note 79892 deleted from function.preg-match by tularis

From: Date: Thu, 03 Jul 2008 21:37:46 +0000
Subject: note 79892 deleted from function.preg-match by tularis
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-141142@lists.php.net to get a copy of this message
Note Submitter: bjorn dot padding at gmail dot com ---- To test if a regular expression is syntactically correct: <? function preg_test($regex) { if (sprintf("%s",@preg_match($regex,'')) == '') { $error = error_get_last(); throw new Exception(substr($error['message'],70)); } else return true; } ?> usage: <? if (preg_test('/.*/i')) print "correct!"; // Returns "correct!" ?> <? if (preg_test('/.**/i')) print "correct!"; // Throws exception with message 'Compilation failed: nothing to repeat at offset 2' ?>

« previous php.notes (#141142) next »