Table des matières

Regular expressions

Several tasks use regular expressions (RegExp) to recognise file names and extract pieces from them. This page gathers the syntaxes and examples.

Where? Field Specifics
Rename regSrc / outputName Groups reused with $1, $2…
AddFile regSrc / outputName Same principle, to build the name of a companion file
Publish to Tracker match Filter Also accepts a simplified syntax (see below)
Get From Tracker Asset Match The group in brackets is the asset name
Photoshop actions Rename Layer, Remove Layers… ! prefix = partial expression

The essentials

Symbol Means Example
. any character a.c → abc, a_c
\. a real dot \.png
\d a digit SC\d\d\d → SC001
\D anything but a digit
* 0 or more times .* → anything
+ 1 or more times \d+ → 1, 12, 123
? 0 or 1 time
{3} exactly 3 times \d{3} → 001
^ / $ start / end of the name ^test
( ) group: piece to reuse (EP\d+)
(A|B) A or B (mov|mp4)

Renaming with groups

Each pair of brackets captures a piece, reused in outputName with $1, $2…

Need Original name Result regSrc outputName
Add a prefix test-Fichier.ext ren-test-Fichier.ext (.*) ren-$1
Remove a prefix test-Fichier.ext Fichier.ext (.*)-(.*) $2
Change the extension test-Fichier.ext test-Fichier.mov (.*)\.ext $1.mov
Reorder test-Fichier.ext Fichier-ext.mov test-(.*)\.(.{3}) $1-$2.mov
Real case ZUK101_BG_002_BGC_V01.jpg ZUK101_LAY_002_BGL_V01.jpg (.*)_BG_(.*)_BGC_(.*$) $1_LAY_$2_BGL_$3
Insert a word Ep001_S001.png Ep001_BG_S001.png (Ep\d+)_(S\d+)\.png $1_BG_$2.png

Simplified syntax (Publish to Tracker)

The match Filter field accepts, in addition to a standard RegExp, a short notation:

Symbol Equivalent to
# a digit [0-9]
@ a letter [a-zA-Z]
% a letter, a digit or a hyphen (Toto-Version03 matches)
. a real dot
* + ? ( ) as in a standard RegExp

Example: PROD###_###_%+_(BOX|ANIM).(mov|jpg)

Extracting an asset name (Get From Tracker)

Version Asset sought Asset Match
CRT122_098_ANM_V04 CRT122_098 (CRT\d+_\d+)_\D+_V\d+

The brackets are mandatory: they mark the “asset” part.

To test an expression before using it, enable the Test Mode of the Rename task, or use a website such as regex101.com.

See also