$re = '/(?m)
(?:
^ \d{2} - \d{4} [^|\r\n]* \|
| \G
)
(?: [^|\r\n]* \| )*
\K
[\r\n]+ (?! [\r\n]* (?: ^ \d{2} - \d{4} | $ ) )
/x';
$str = '00-1234T|
Data|Commments|
12-3456|Some data|Notes|
65-8436ZZ|Data|
|
45-4576AA|Some data|Comments|
98-4392REV|Data|
|
00-5432|Some Data|Some Comments|
';
$subst = "#CRLF#";
$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