I’m trying to insert some text midway through some HTML content using the following regex:
if (preg_match('/(.*<\/a><\/p>)(.*?)/Ui', $content, $match))
$custom_content = $match[1] . $title . $match[2];
The result I want is that $title is inserted into the HTML immediately after the first </a></p> is encountered. This much is working, however the second capture group always remains empty, regardless of the greedy / ungreedy combinations I use. The result is that the remainder of the content after the </a></p> is not appended to the result.
What am I doing wrong here?
Why bother capturing the part you don’t care about. Simply replace the first group with itself plus
$title, eg