protected function posix2Pcre(
        string $regex,
        array $names = ["params", "named"]
    ): string {
        $counters = [];
        foreach ($names as $type) {
            $regex = preg_replace_callback(
                "~\[:{$type}:\]~",
                function() use (&$counters, $type) {
                    if (isset($counters[$type]) === false) {
                        $counters[$type] = 0;
                    }
                    $counters[$type]++;
                    $changed = "(?P<{$type}{$counters[$type]}>.+?)";
                    return $changed;
                },
                    $regex
                );
        }

        return $regex;
    }
protected function posix2Pcre(
        string $regex,
        array $names = ["params", "named"]
    ): string {
        $counters = [];
        foreach ($names as $type) {
            $regex = preg_replace_callback(
                "~\[:{$type}:\]~",
                function() use (&$counters, $type) {
                    if (isset($counters[$type]) === false) {
                        $counters[$type] = 0;
                    }
                    $counters[$type]++;
                    $changed = "(?P<{$type}{$counters[$type]}>.+?)";
                    return $changed;
                },
                    $regex
                );
        }

        return $regex;
    }
protected function posix2Pcre ( string $ regex , array $ names = [ "params" , "named" ] ) : string { $ counters = [ ] ; foreach ( $ names as $ type ) { $ regex = preg_replace_callback ( "~\[:{$type}:\]~" , function ( ) use ( & $ counters , $ type ) { if ( isset ( $ counters [ $ type ] ) === false ) { $ counters [ $ type ] = 0 ; } $ counters [ $ type ] ++ ; $ changed = "(?P<{$type}{$counters[$type]}>.+?)" ; return $ changed ; } , $ regex ) ; } return $ regex ; }
POSIX named class to PCRE capturing group

Replace the special POSIX named classes with normal named capturing
groups.

@param string $regex Raw regexp string
@param array $names POSIX class names array, default: ["params", "named"]
@return string Replaced regexp string
POSIX named class to PCRE capturing group