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 {
if ($addon = $this->argument('addon')) {
$this->package = Str::startsWith($addon, '/')
? preg_replace('/.*\/([^\/]+\/[^\/]+)$/', '$1', $addon)
: $addon;
}
<?php $find = ' ],';
$contents = preg_replace('/'.$find.'/', $find."\n\n".$newConfig, $contents);
<?php $filesystemsPath = config_path('filesystems.php');
$config = $this->files->get($filesystemsPath);
$diskRegex = "/\s{8}['\"]{$disk}['\"]\X*\s{8}\],?+\n\n?+/mU";
$updatedConfig = preg_replace($diskRegex, '', $config);
$this->files->put($filesystemsPath, $updatedConfig);
<?php protected function preparePath($path)
{
$folder = preg_replace('/(.*)\/[^\/]+\.[^\/]+/', '$1', $path);
if (! $this->files->exists($folder)) {
$this->files->makeDirectory($folder, 0755, true);
<?php $preUpdateCmdsExist = Arr::get(json_decode($composerJson, true), 'scripts.pre-update-cmd', false);
if ($preUpdateCmdsExist) {
$composerJson = preg_replace('/("pre-update-cmd".*\n)/m', "$1 \"$preUpdateCmdScript\",\n", $composerJson);
} else {
$composerJson = preg_replace('/("scripts".*\n)/m', '$1'.$preUpdateCmdsArray, $composerJson);
}
<?php if ($preUpdateCmdsExist) {
$composerJson = preg_replace('/("pre-update-cmd".*\n)/m', "$1 \"$preUpdateCmdScript\",\n", $composerJson);
} else {
$composerJson = preg_replace('/("scripts".*\n)/m', '$1'.$preUpdateCmdsArray, $composerJson);
}
$success = Arr::get(json_decode($composerJson, true), 'scripts.pre-update-cmd', false);
<?php if (! $this->colorized) {
$output = preg_replace('/\\e\[[0-9]+m/', '', $output);
}
<?php }
$output = preg_replace('/\\n$/', '', $output);
return $output;
}
<?php public function getBasePath()
{
return preg_replace('/(.*)\/$/', '$1', $this->basePath);
}
<?php $path = str_replace('\\', '/', $path);
return preg_replace('#(^|[^:])//+#', '\\1/', $path);
}
<?php public function removeSiteUrl($url)
{
return preg_replace('#^'.Config::getSiteUrl().'#', '/', $url);
}
<?php $dest = $this->normalizePath($dest);
foreach ($this->getFilesRecursively($src) as $old) {
$new = preg_replace('#^'.$src.'#', $dest, $old);
$this->copy($old, $new, $overwrite);
}
}
<?php $dest = $this->normalizePath($dest);
foreach ($this->getFilesRecursively($src) as $old) {
$new = preg_replace('#^'.$src.'#', $dest, $old);
$this->move($old, $new, $overwrite);
}
<?php '#</tr>#' => '%E%',
];
$phpInfoStr = preg_replace(array_keys($replacePairs), array_values($replacePairs), $phpInfoStr);
$sections = explode('<h2>', strip_tags($phpInfoStr, '<h2><th><td>'));
unset($sections[0]);
<?php '-',
'_',
'.',
], ' ', preg_replace('/(?<![A-Z])[A-Z]/', ' \0', $name))));
return $label;
}