- print_r: documentation ( source)
- preg_match_all: documentation ( source)
<?php
$re = "/(?<=^\\S|\\s\\S|\\s)[RD]/g";
$str = "-D-K4_NNNN_M116_R1_001.gz _D-K4_NNNN_M56_R1_001.gz R-K4_NNNN_KQ9_R1_001.gz D-K4_NNNN_M987_R1_001.gz _R-K4_NNNN_M987_R1_001.gz";
preg_match_all($re, $str, $matches);
echo '<pre>';
print_r($matches);
echo '</pre>';