[lang-ref] ( replace_first_with_regexp ) ( php )
<?php
public function testReplaceFirstWithRegexp(): void
{
// preg_replace($pattern, $after, $text, limit: 1)
$text_org = "abc def ghi\nabc def ghi";
$pattern = '/d.f/';
$s_new = '!!DEF!!';
$text_new = preg_replace($pattern, $s_new, $text_org, 1);
$this->assertNotFalse($text_new);
$this->assertSame("abc !!DEF!! ghi\nabc def ghi", $text_new);
}