$re = '/<div\ id=\"adblock_1\".*?>
(<div.*?>(?1)*?<\/div>|.)*?
<\/div>/isx';
$str = '<div>
text0
<div id="adblock_1" >
<div class="warning_block">
<div id="adblock_detected_message">
<div>Text1<div>abc</div></div>
<div>Text2</div>
</div>
<div id="adblock_close_button">
<img src="close_button.png" alt="close button" />
</div>
</div>
</div>
text4
</div>';
$subst = "A";
$result = preg_replace($re, $subst, $str, 1);
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