protected function textToRegExp(string $text): string
    {
        // preg_quote() is useless with /x modifier: https://3v4l.org/brdeT

        if (false === strpos($this->modifiers, 'x') || !preg_match('~[\\s/#]|\\\\E~', $text)) {
            return preg_quote($text, '/');
        }

        // foo\Efoo --> \Qfoo\E\\\QEfoo\E
        // ---^====       ---  ^^  ====
        //
        // foo/foo  --> \Qfoo\E\/\Qfoo\E
        // ---^===        ---  ^^  ===
        return '\\Q' . strtr($text, ['\\E' => '\\E\\\\\\QE', '/' => '\\E\\/\\Q']) . '\\E';
    }