-
-
Save ameenross/49d1789fccec34da82f8ba6e6e7de87a to your computer and use it in GitHub Desktop.
PHP: Check if string is valid regular expression
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* @param string $regex | |
* @return bool | |
*/ | |
function isValidRegularExpression($regex) { | |
set_error_handler(function() {}, E_WARNING); | |
$valid = preg_match($regex, null) !== FALSE; | |
restore_error_handler(); | |
return $valid; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment