$re = '/[^.]+\.(?=[^.]+$)/m';
$str = '// hash starts with number
/css/app.style.7fef363d5a8c4ef2458c.css
/css/app.bundle.7fef363d5a8c4ef2458c.css
/css/app.chunk.7fef363d5a8c4ef2458c.css
/css/app.7fef363d5a8c4ef2458c.css
/css/loading-animation.7fef363d5a8c4ef2458c.css
// hash starts with letter
/css/app.style.b3bcb606396f0c96623a.css
/css/app.bundle.b3bcb606396f0c96623a.css
/css/app.chunk.b3bcb606396f0c96623a.css
/css/app.b3bcb606396f0c96623a.css
// no preceeding dot separated name before the hash
/css/loading-animation.b3bcb606396f0c96623a.css
/css/app.b3bcb606396f0c96623a.js';
$subst = "";
$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