$re = '/(DTP\*431.*?)REF\*6R/s';
$str = 'DTP*431*D8*20150101~
[variable text in between]
LX*1~
DTP*472*RD8*20150102-20150102~
REF*6R*[more information]~
[variable text in between]
DTP*431*D8*20141231~
[variable text in between]
LX*1~
DTP*472*RD8*20150101-20150101~
REF*6R*[more information]~';
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