Skip to content

Instantly share code, notes, and snippets.

View ameenross's full-sized avatar

Ameen Ross ameenross

View GitHub Profile
@ameenross
ameenross / check_regex.php
Last active April 29, 2021 10:34 — forked from smichaelsen/check_regex.php
PHP: Check if string is valid regular expression
<?php
/**
* @param string $regex
* @return bool
*/
function isValidRegularExpression($regex) {
set_error_handler(function() {}, E_WARNING);
$valid = preg_match($regex, null) !== FALSE;
restore_error_handler();