protected function escapeExpressions($string, $allowWildcard = false)
    {
        if ($allowWildcard) {
            $reservedCharacters = preg_quote('+-&|!(){}[]^"~?:\\ ');
        } else {
            $reservedCharacters = preg_quote('+-&|!(){}[]^"~*?:\\ ');
        }

        return preg_replace_callback(
            '/([' . $reservedCharacters . '])/',
            function ($matches) {
                return '\\' . $matches[0];
            },
            $string
        );
    }