$re = '/<(?<tagName>\w+)(([^<]*\/>)|(.*?\/(\k<tagName>)>))/m';
$str = ' <child name = "child_name1" type = "child_type1"> <subchild id = "1" auth="auth1">Value1</subchild> </child> <child name = "child_name2" type = "child_type2"> <subchild id = "2" auth="auth1">Value2</subchild> <subchild id = "3" auth="auth2">Value3</subchild> <subchild id = "4" auth="auth3"></subchild> <subchild id = "5" auth="auth3"/> </child>';
preg_match_all($re, $str, $matches, PREG_SET_ORDER, 0);
// Print the entire match result
var_dump($matches);
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