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 foreach ($composerFiles as $composerFile) {

    $contents = $filesystem->read($composerFile);

    $mainVersionRegex = preg_quote($mainVersion, '~');

    $updated = preg_replace('~("league/flysystem": "\\^[a-zA-Z0-9\\.-]+")~ms', '"league/flysystem": "^'.$mainVersion.'"', $contents);

    $filesystem->write($composerFile, $updated);

}
<?php     private function throwStagedException(string $method, $path): void

    {

        $method = preg_replace('~.+::~', '', $method);

        $key = join('@', [$method, $path]);



        if ( ! array_key_exists($key, $this->stagedExceptions)) {
<?php             }



            if (preg_match('#^.*:$#', $item)) {

                $base = preg_replace('~^\./*|:$~', '', $item);

                continue;

            }
<?php     private function normalizeWindowsObject(string $item, string $base): StorageAttributes

    {

        $item = preg_replace('#\s+#', ' ', trim($item), 3);

        $parts = explode(' ', $item, 4);



        if (count($parts) !== 4) {
<?php     private function normalizeUnixObject(string $item, string $base): StorageAttributes

    {

        $item = preg_replace('#\s+#', ' ', trim($item), 7);

        $parts = explode(' ', $item, 9);



        if (count($parts) !== 9) {
<?php         }




        $responseCode = $response ? (int) preg_replace('/\D/', '', implode('', $response)) : false;



        return $responseCode === 200;

    }