I would like to use the PHP function preg_replace to remove the appended dimensions in image filenames. Our CMS adds dimensions to the end of the filename, right before the extension. For legacy reasons, the naming conventions are inconsistent: sometimes an underscore preceeds, other times, a dash.
It would be super useful to strip the dimensions out in my frontend code.
Is there a single PHP regular expression that would match in these scenarios:
Example-Filename,-lorem-ipsum_999x999.jpg
[need to match: _999x999]
Example-Filename2-lorem,-ipsum-42x42.PNG
[need to match: -42x42]
Example-Filename3-lorem-Ipsum-dolor-blah_0128x0256.jpeg
[need to match: _0128x0256]