Regular expressions use a formalized syntax to achieve complex find and replace operations by matching specified patterns of text. The DF Studio Rename Images tool allows the use of regular expressions to replace text in the filenames of assets.
Understanding and composing regular expression patterns can be challenging, but they provide an opportunity to automate solutions that might otherwise require a great deal of manual effort.
Useful Patterns
The following frequently-used patterns can be used and customized to perform advanced matches.
Append
The custom character $ matches “end of line” in regular expressions. Thus, finding $ and replacing it with any value appends that value to the end of the existing text.
Example Text: title_shoot_0001.jpg
Pattern: $
Replacement: _photographer
Result: title_shoot_0001_photographer.jpg
Interactive example: regex101.com/r/qYXdV6/1
Note that DF Studio only matches the portion of the filename before the extension (e.g., .jpg).
Prepend
The custom character ^ matches “start of line” in regular expressions. Prepend a value to existing text by replacing ^ with the desired value.
Example Text: shoot_0001.jpg
Pattern: ^
Replacement: title_
Result: title_shoot_0001.jpg
Interactive example: regex101.com/r/Lu09ID/1
Optional Characters
The custom character ? lets the regular expression parser know that the previous character in the pattern is optional.
Example Text:
title_setup_0001.jpg title_setups_0002.jpg title_setup_0003.jpg
Pattern: _setups?_
Replacement: _BTS_
Result:
title_BTS_0001.jpg title_BTS_0002.jpg title_BTS_0003.jpg
Interactive example: regex101.com/r/u55mzT/1
Numeric Characters
The custom code \d represents any numeral (or “digit”).
Example Text:
title_10212015_0001.jpg title_10222015_0002.jpg title_10232015_0003.jpg
Pattern: 102\d2015
Replacement: 10212015
Result:
title_10212015_0001.jpg title_10212015_0002.jpg title_10212015_0003.jpg
Interactive example: regex101.com/r/fdeUn6/1
Repetition
Specifying a number or range of numbers between curly braces {} indicates that the previous character or pattern should match that number of times.
Example Text:
title_SC001_0001.jpg title_SC10_0002.jpg title_SC1150_0003.jpg
Pattern: SC\d{1,5}
Replacement: SC-coverage
Result:
title_SC-coverage_0001.jpg title_SC-coverage_0002.jpg title_SC-coverage_0003.jpg
Interactive example: regex101.com/r/eZhAA6/1
Escape
When it’s necessary to match a custom regular expression character literally (that is, as the character itself and not its regular expression function), a backslash \ should be added before the character, to “escape” the custom regular expression use of that character.
Example Text: title_which-one?_0001.jpg
Pattern: \?
Replacement:
Result: title_which-one_0001.jpg
Interactive example: regex101.com/r/9NsIyK/1
Workflow Example
For a step-by-step example that uses regular expressions to rename multiple files, see Rename and Renumber Assets.
Learn More
There are many resources available online for learning about regular expressions. The following tools provide opportunities to test and learn the proper syntax: