preg_replace

Supported Versions: PHP 4, PHP 5, PHP 7, PHP 8
Perform a regular expression search and replace
<?php preg_replace(    string|array $pattern,    string|array $replacement,    string|array $subject,    int $limit = -1,    int &$count = null): string|array|null
<?php     public static function getPrintableTestCaseName(): string

    {

        return preg_replace('/P\\\/', '', self::class, 1);

    }
<?php         throw new ExpectationFailedException(sprintf(

            'Expecting %s not %s %s.',

            $toString($this->original->value),

            strtolower((string) preg_replace('/(?<!\ )[A-Z]/', ' $0', $name)),

            implode(' ', array_map(fn (mixed $argument): string => $toString($argument), $arguments)),

        ));

    }
<?php         $relativePath = str_replace(DIRECTORY_SEPARATOR, '\\', $relativePath);




        $relativePath = (string) preg_replace('|%[a-fA-F0-9][a-fA-F0-9]|', '', $relativePath);


        $relativePath = str_replace(array_map(fn (string $quote): string => sprintf('\\%s', $quote), ['\'', '"']), '', $relativePath);
<?php         $relativePath = str_replace(array_map(fn (string $quote): string => sprintf('\\%s', $quote), ['\'', '"']), '', $relativePath);


        $relativePath = (string) preg_replace('/[^A-Za-z0-9\\\\]/', '', $relativePath);



        $classFQN = 'P\\'.$relativePath;
<?php             if ('\\' === DIRECTORY_SEPARATOR || preg_match('~\A[A-Z]:(?![^/\\\\])~i', $path) > 0) {

                $path = (string) preg_replace_callback('~^(?P<drive>[a-z]+:\\\)~i', fn (array $match): string => strtolower($match['drive']), $path);



                $startChar = strtolower((string) preg_replace('~^([a-z]+:\\\).*$~i', '$1', __DIR__));

            }



            return str_starts_with($path, $startChar)
<?php                     View::render('components.two-column-detail', [

                        'left' => $this->colorizeOptions($argument),

                        'right' => preg_replace(['/</', '/>/'], ['[', ']'], $description),

                    ]);

                }

            }
<?php     private function colorizeOptions(string $argument): string

    {

        return (string) preg_replace(

            ['/</', '/>/', '/(-+[\w-]+)/'],

            ['[', ']', '<fg=blue;options=bold>$1</>'],

            $argument

        );

    }
<?php             return;

        }



        $feedbackItems = (string) preg_replace('/ +\\d+ \\/ \\d+ \\( ?\\d+%\\)\\s*/', '', $feedbackItems);



        $actualTestCount = strlen($feedbackItems);

        for ($index = 0; $index < $actualTestCount; $index++) {
<?php             '# Object \(…\)#' => '',

        ];



        return (string) preg_replace(array_keys($map), array_values($map), $this->exporter->shortenedExport($value));

    }

}
<?php         $code = self::PREFIX.str_replace(' ', '_', $code);




        return (string) preg_replace('/[^a-zA-Z0-9_\x80-\xff]/', '_', $code);

    }
<?php expect()->pipe('toMatchSnapshot', function (Closure $next) {

    if (is_string($this->value)) {

        $this->value = preg_replace(

            '/name="_token" value=".*"/',

            'name="_token" value="1"',

            $this->value

        );

    }



    return $next();
<?php function removeAnsiEscapeSequences(string $input): ?string

{

    return preg_replace('#\\x1b[[][^A-Za-z]*[A-Za-z]#', '', $input);

}
<?php <?php



it('may start with P', function (string $real, string $toBePrinted) {

    $printed = preg_replace('/P\\\/', '', $real, 1);



    expect($printed)->toBe($toBePrinted);

})->with([
<?php     try {

        $xml = new SimpleXMLElement(preg_replace("/(<\/?)(\w+):([^>]*>)/", '$1$2$3', $rawXmlContent));



        return json_decode(json_encode((array) $xml), true);

    } catch (Exception $exception) {
<?php         $process->run();



        return preg_replace([

            '#\\x1b[[][^A-Za-z]*[A-Za-z]#',

            '/(Tests\\\PHPUnit\\\CustomAffixes\\\InvalidTestName)([A-Za-z0-9]*)/',

        ], [

            '',

            '$1',

        ], $process->getOutput());

    };



    if (getenv('REBUILD_SNAPSHOTS')) {