是否可以在 PHP 中确定怀孕模式是否有效


Is it possible in PHP to determine if a preg pattern is valid

preg_match() 将返回

preg_match() [function.preg-match]: Delimiter must not be alphanumeric or backslash

如果模式格式不正确。是否有一个函数可以在将模式传递到 preg_match() 之前确定模式是否格式正确(TRUE 或 FALSE)?

$match = preg_match('regex', 'string');
if ($match === false) {
    // failed
} elseif ($match == false) {
    // did not matched
} else {
    // matched
}