If you are unfamiliar with regular expressions, please read the Regular Expressions Support in A Better Finder Rename help topic first.
This action is specifically intended to allow you to easily re-arrange parts of existing file names using the power of regular expressions to match the different file name parts.
You specify a “pattern” as a regular expression with capture groups and then use the capture variables $1, $2, $3
in the “substitution expression” to re-arrange the different parts of the name. A Better Finder Rename shows the
contents of each capture variable in its own column of the preview table to help you tweak your settings.
Capture groups and capture variables are explained in more detail in the Basic Regular Expression Syntax help topic.
Two rules set this action apart from the Replace regular expression action:
^ and $. If it does not match the entire name, the name is left unchanged and the capture columns in the
preview stay empty. You never need to type the anchors yourself, but it does no harm if you do.As a simple example of using this feature, let’s swap the first and the second word of a couple of two word file names.
We start by defining a regular expression with two capture groups, e.g. (.*) (.*) defines two capture groups with
arbitrary content separated by a space.
The substitution expression is a string in which we can substitute the variables $1, $2, $3 with the content of
the capture group with the same index.
$2 $1 will simply swap the contents of the first and the second capture groups.
hello world -> world helloJohn Smith -> Smith JohnAdding arbitrary text around the capture variables simply includes this text in the new file name, e.g.
Dear Mr $2 in the above John Smith example would yield Dear Mr Smith.
Because the pattern must match the whole name, a partial pattern does nothing:
(\d+) with substitution Hawaii_$1 leaves IMG_4821 unchanged, because IMG_ is not matchedIMG_(\d+) with substitution Hawaii_$1 turns IMG_4821 into Hawaii_4821To pick something out of the middle of a name, let the pattern swallow the parts you do not want:
.*?(INV-\d+).* with substitution $1 turns Scan of INV-20419 final into INV-20419The action supports capture variables $1 to $8; $0 holds the whole name. The older \1, \2, \3 syntax is
accepted as well.
Since version 12.19 the action can run on two engines, see Regular Expressions Support.
\U, \L, \u, \l), lookahead and lookbehind.The only difference in behaviour between the two engines is that the legacy engine is not anchored: it uses the
first place in the name where the pattern matches and discards the rest of the name. With the (\d+) example above
the legacy engine would produce Hawaii_4821 where the modern engine leaves the name alone. Old presets that rely on
this will keep working as long as the checkbox stays ticked; when you write a new pattern, make it match the whole
name instead.