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     protected function extractChannelKeys($pattern, $channel)

    {

        preg_match('/^'.preg_replace('/\{(.*?)\}/', '(?<$1>[^\.]+)', $pattern).'/', $channel, $keys);



        return $keys;

    }
<?php     protected function channelNameMatchesPattern($channel, $pattern)

    {

        return preg_match('/^'.preg_replace('/\{(.*?)\}/', '([^\.]+)', $pattern).'$/', $channel);

    }
<?php     public function cleanRateLimiterKey($key)

    {

        return preg_replace('/&([a-z])[a-z]+;/i', '$1', htmlentities($key));

    }

}
<?php         if (! $this->output->isVerbose()) {

            $command = str_replace([Application::phpBinary(), Application::artisanBinary()], [

                'php',

                preg_replace("#['\"]#", '', Application::artisanBinary()),

            ], $command);

        }
<?php         ));




        $command = preg_replace("#(php artisan [\w\-:]+) (.+)#", '$1 <fg=yellow;options=bold>$2</>', $command);



        return [sprintf(

            '  <fg=yellow>%s</> <fg=#6C7280>%s</> %s<fg=#6C7280>%s %s%s %s</>',
<?php     public function __invoke($string)

    {

        return preg_replace('/\[([^\]]+)\]/', '<options=bold>[$1]</>', (string) $string);

    }

}
<?php             Mutators\EnsureRelativePaths::class,

        ]);



        $descriptionWidth = mb_strlen(preg_replace("/\<[\w=#\/\;,:.&,%?]+\>|\\e\[\d+m/", '$1', $description) ?? '');



        $this->output->write("  $description ", false, $verbosity);
<?php     protected function wrapJsonPath($value, $delimiter = '->')

    {

        $value = preg_replace("/([\\\\]+)?\\'/", "''", $value);



        $jsonPath = collect(explode($delimiter, $value))

            ->map(fn ($segment) => $this->wrapJsonPathSegment($segment))
<?php             $alias ??= Str::snake(

                preg_replace('/[^[:alnum:][:space:]_]/u', '', "$name $function {$this->getQuery()->getGrammar()->getValue($column)}")

            );



            if ($function === 'exists') {
<?php     protected function removeLeadingBoolean($value)

    {

        return preg_replace('/and |or /i', '', $value, 1);

    }
<?php     protected function removeAutoIncrementingState(string $path)

    {

        $this->files->put($path, preg_replace(

            '/\s+AUTO_INCREMENT=[0-9]+/iu',

            '',

            $this->files->get($path)

        ));

    }
<?php     protected function makeListeners($event, $listeners)

    {

        foreach ($listeners as $listener) {

            $listener = preg_replace('/@.+$/', '', $listener);



            $this->callSilent('make:listener', array_filter(

                ['name' => $listener, '--event' => $event]
<?php     protected function writeNewEnvironmentFileWith($key)

    {

        $replaced = preg_replace(

            $this->keyReplacementPattern(),

            'APP_KEY='.$key,

            $input = file_get_contents($this->laravel->environmentFilePath())

        );



        if ($replaced === $input || $replaced === null) {

            $this->error('Unable to set application key. No APP_KEY variable was found in the .env file.');
<?php             array_keys($replace), array_values($replace), $stub

        );



        return preg_replace(

            vsprintf('/use %s;[\r\n]+use %s;/', [

                preg_quote($namespacedModel, '/'),

                preg_quote($namespacedModel, '/'),

            ]),

            "use {$namespacedModel};",

            $stub

        );

    }
<?php                 '  <fg=white;options=bold>%s</> %s<fg=white>%s</><fg=#6C7280>%s %s</>',

                $method,

                $spaces,

                preg_replace('#({[^}]+})#', '<fg=yellow>$1</>', $uri),

                $dots,

                str_replace('   ', ' › ', $action ?? ''),

            ), $this->output->isVerbose() && ! empty($middleware) ? "<fg=#6C7280>$middleware</>" : null];