$re = '/(?<=_)[0-9_]*/m';
$str = 'DM1_65_78109
SL1_78_72947
DM1_813_1881
Input is DM2_793_1808
Input is DM1_SL1_609_604980 ';
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