Regular Expressions 101

Community Patterns

Remove _1 suffix from image filenames

3

Regular Expression
PCRE (PHP <7.3)

/
_([_\d]*)[.]
/
g

Description

Remove autogenerated file name suffixes from images whilst preserving the extension (e.g. .jpg)

These suffixes are usually added when filename already exists in the directory an image is being saved to by an application.

Magento is a fine example of a system that does this.

Submitted by John Hughes - 8 years ago