我有这个文件和regex:
$pattern = '/.*services {1,}:/';
$services = file_get_contents($services_file);
preg_match($pattern, $services, $matches);
dump($matches)
我能够在文件中找到我的表达式,现在我想在它后面写一些东西。
使用preg_replace()
。$0
与模式完全匹配,并在其后面添加$replacement
文本:
$result = preg_replace($pattern, "$0$replacement", $services);
file_put_contents($services_file, $result);