GrumPHP\Util\Regex::isRegex PHP Метод

isRegex() приватный Метод

Checks whether the string is a regex.
private isRegex ( string $string ) : boolean
$string string
Результат boolean Whether the given string is a regex
    private function isRegex($string)
    {
        if (preg_match('/^(.{3,}?)[' . self::ALLOWED_MODIFIERS . ']*$/', $string, $m)) {
            $start = substr($m[1], 0, 1);
            $end = substr($m[1], -1);
            if ($start === $end) {
                return !preg_match('/[*?[:alnum:] \\\\]/', $start);
            }
            foreach ([['{', '}'], ['(', ')'], ['[', ']'], ['<', '>']] as $delimiters) {
                if ($start === $delimiters[0] && $end === $delimiters[1]) {
                    return true;
                }
            }
        }
        return false;
    }