$re = '/[\w\+\-]+\.\w+\.(?<EPOCH>\d+)(?<AV>\.av)?\.mat/';
$str = 'AvAnalysisTill20Kepoch_onlyW.png
Program.30_07_2017_14_03_31.1.json
Program.30_07_2017_14_03_31.1.mat
Program.30_07_2017_14_03_31.10002.mat
Program.30_07_2017_14_03_31.10005.mat
Program.30_07_2017_14_03_31.10005.av.mat
Program.30_07_2017_14_03_31.10005.mat
Program.30_07_2017_14_03_31.10008.mat
Program.30_07_2017_14_03_31.10011.mat
Program.30_07_2017_14_03_31.10014.mat
Program.30_07_2017_14_03_31.10017.mat
Program.30_07_2017_14_03_31.1002.mat
Program.30_07_2017_14_03_31.10020.mat
Program.30_07_2017_14_03_31.10023.mat
Program.30_07_2017_14_03_31.10026.mat
Program.30_07_2017_14_03_31.10029.mat
Program.30_07_2017_14_03_31.10032.mat
Program.30_07_2017_14_03_31.10035.mat
Program.30_07_2017_14_03_31.10038.mat
Program.30_07_2017_14_03_31.10041.mat
Program.30_07_2017_14_03_31.10044.mat
Program.30_07_2017_14_03_31.10047.mat
Program.30_07_2017_14_03_31.1005.mat
UBUNTU_30x300w30r3E-2.02_08_2017_12_09_36.19950.mat
UBUNTU_30x300w30r3E-2.02_08_2017_12_09_36.19953.mat
UBUNTU_30x300w30r3E-2.02_08_2017_12_09_36.19956.mat
UBUNTU_30x300w30r3E-2.02_08_2017_12_09_36.19959.mat
UBUNTU_30x300w30r3E-2.02_08_2017_12_09_36.19962.mat
UBUNTU_30x300w30r3E-2.02_08_2017_12_09_36.19965.mat
UBUNTU_30x300w30r3E-2.02_08_2017_12_09_36.19968.mat
UBUNTU_30x300w30r3E-2.02_08_2017_12_09_36.19971.mat
UBUNTU_30x300w30r3E-2.02_08_2017_12_09_36.19974.mat
UBUNTU_30x300w30r3E-2.02_08_2017_12_09_36.19977.mat
UBUNTU_30x300w30r3E-2.02_08_2017_12_09_36.19980.mat
UBUNTU_30x300w30r3E-2.02_08_2017_12_09_36.19983.mat
UBUNTU_30x300w30r3E-2.02_08_2017_12_09_36.19986.mat
UBUNTU_30x300w30r3E-2.02_08_2017_12_09_36.19989.mat
UBUNTU_30x300w30r3E-2.02_08_2017_12_09_36.19992.mat
UBUNTU_30x300w30r3E-2.02_08_2017_12_09_36.19995.mat
UBUNTU_30x300w30r3E-2.02_08_2017_12_09_36.19998.mat
UBUNTU_30x300w30r3E-2.02_08_2017_12_09_36.20000.mat
';
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