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';
    }
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';
    }
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' ; }
Escape plain text to be a RegExp matching the text

Native `preg_quote()` does not care about possible `/x` modifier and does
not take modifiers with delimiter. So, with `/x` modifier we use `\Q...\E`
instead if `$text` contains some `/x`-mode meta characters: `#` or spaces.
@param string $text Plain text
@return string RegExp matching the text
@see https://3v4l.org/brdeT Comparison between `preg_quote()` and `\Q...\E`
when `/x` modifier is used
@see https://3v4l.org/tnnap This function test
Escape plain text to be a RegExp matching the text