$re = '/<tr\b[^<]*>[^<]*(?:<(?!tr\b)[^<]*)*#HIDETR#[^<]*(?:<(?!\/tr>)[^<]*)*<\/tr>/';
$str = 'HIDE TR DOUBLE TABLE
<table border="1" cellpadding="1" cellspacing="1" height="273" width="1100">
<tbody>
<tr>
<td>asdfasdfasd</td>
<td>a sdfasdf asd</td>
</tr>
<tr>
<td>fasdfasdfasd</td>
<td>
<table border="1" cellpadding="1" cellspacing="1" style="width:500px;">
<tbody>
<tr>
<td>#HIDETR#</td>
<td>sdfasd</td>
</tr>
<tr>
<td>a sdfasd</td>
<td>a sdf</td>
</tr>
<tr>
<td>fasdf asdfa</td>
<td>ds afasd</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
<br />
HIDE TR TABLE<br />
<table border="1" cellpadding="1" cellspacing="1" style="width:500px;">
<tbody>
<tr>
<td>asdfsa df</td>
<td>a sdfasdf</td>
</tr>
<tr>
<td>sdfa sdf as</td>
<td>#HIDETR#</td>
</tr>
</tbody>
</table>';
$subst = "<tr><td>removed line<td></tr>";
$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