Используйте положительные / отрицательные взгляды.
$result = preg_replace('/(?<=Title:).*(?=Article Body:)/s', '\nTest\n', $subject);
Приведенное выше регулярное выражение заменит все, что находится внутри Заголовок: ... Тело статьи: с \ nTest \ n
Объяснение:
"
(?<= # Assert that the regex below can be matched, with the match ending at this position (positive lookbehind)
Title: # Match the characters “Title:” literally
)
. # Match any single character
* # Between zero and unlimited times, as many times as possible, giving back as needed (greedy)
(?= # Assert that the regex below can be matched, starting at this position (positive lookahead)
Article\ Body: # Match the characters “Article Body:” literally
)
"