$re = '@(<blockquote>(?:(?!</?blockquote).)*?)<p>(.*?)</p>((?:(?!</?blockquote).)*</blockquote>)@s';
$str = '<blockquote>
<div>paragraph 1</div>
</blockquote>
<p>paragraph 1 outside blockquote</p>
<blockquote>
<div>paragraph 2</div>
<p>paragraph 3</p>
</blockquote>
<p>paragraph 2 outside blockquote</p>';
$subst = "\1<div>\2</div>\3";
$result = preg_replace($re, $subst, $str);
echo "The result of the substitution is ".$result;
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for PHP, please visit: http://php.net/manual/en/ref.pcre.php