$text = '
<h2>This is the simplest string</h2>
<p>anything</p>
<h3>Another one</h3>
';
$pattern = "/<(h2|h3)([^>]*)>(.*)<\/\1>/";
preg_replace_callback($pattern, 'handleMatched', $text);
function handleMatched($m) {
print_r($m);
}
$pattern = "/<(h2|h3)([^>]*)>(.*)<\/\g1>/";
php > var_dump("\1", '\1', "\g1", '\g1', "\\1");
string(1) ""
string(2) "\1"
string(3) "\g1"
string(3) "\g1"
string(2) "\1"