I am trying to strip all non letters from a file path, but I need to leave the extension at the end.
$text = cat.jpg
$text = preg_replace('/[^\\pL\d]+/u', '-', $text);
You can use this regex based on alternation and negative lookahead for your search:
[^\pL\pN.]+ # Search 1 or more of any char that is not DOT and letter and number (unicode) | # OR \. # search for DOT (?![^.]+$) # negative lookahead to skip DOT that is just before file extension
In PHP code:
$text = preg_replace('/[^\pL\pN.]+|\.(?![^.]+$)/u', '-', $text);