$re = '/^(\w+) +\w+ +(?:\[[^\]]+\] *)?(\S.*?)(?: +(\([^)]+\)))?$/m';
$str = '0000 10 Text("TOTAL,SOME RANDOM TEXT") (1122aabb)
0010 5 D==1122aabb (1122aabb)
0015 17 Text("AND,SOME,MORE") (00000001)
002c 5 D==1 (1)
0031 1 !D (ccdd3344)
0032 5 D==ccdd3344 (ccdd3344)
0037 2 !1 (1)
0039 0 [AAAA] Fff
0039 1 [BBBB] Aaa
003a 6 N(05, eeff5566) (eeff5566)
0040 1 Qq
0041 2 $ab ([String]:"Unknown")
0043 f Call A/SomeFunc-X
0052 1 cd';
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