From ea9db448fbcc85b0b3f627ada936a9a303e4a665 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Tim=20D=C3=BCsterhus?= Date: Thu, 22 Dec 2011 20:34:41 +0100 Subject: [PATCH] Adding \wcf\system\Regex::isValid() --- .../install/files/lib/system/Regex.class.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/wcfsetup/install/files/lib/system/Regex.class.php b/wcfsetup/install/files/lib/system/Regex.class.php index 966f698a2b..f079ed49c8 100644 --- a/wcfsetup/install/files/lib/system/Regex.class.php +++ b/wcfsetup/install/files/lib/system/Regex.class.php @@ -103,6 +103,22 @@ final class Regex { return $this->match($string); } + /** + * Checks whether the regex is syntactically correct. + * + * @return boolean + */ + public function isValid() { + try { + $this->match(''); // we don't care about the result, we only care about the exception + return true; + } + catch (SystemException $e) { + // we have a syntax error now + return false; + } + } + /** * Checks whether the regex matches the given string. * -- 2.20.1