OK, I’m quotng the relevant parts from the documentation.
Item scanning: The next two actions allow you to scan the name or text of a document and use the results when found. …
- Scan Name: Scans the name of the file.
…
The following four parameters are used with the Scan Name and Scan Text actions. …
- Regular Expression: Items in parentheses are captured; items outside parentheses are ignored. You can specify multiple captures in an expression. Using the captured text in subsequent actions is specified by using backslash,
\
, and the number of the capture, starting at1
. Note we use Apple’s NSRegularExpression which supports the ICU regular expression syntax.
So you have to use a regular expression, because it is not possible otherwise to refer to parts of the match.
The expression itself should look like this
(\d{4})(\d\d)(\d\d)(?:_?\d{4})(-.*)
and the replacement like this
\1_\2_\3\4
Explanation: \d
is RegEx’ish for [0-9], think of “digits”. So we’re first capturing 4, 2, and another 2 digits in the capturing groups (delimited by parenthesis) 1, 2 and 3. Then comes a non-capturing group (?:...)
. It looks for an optional (?
) underscore, followed by four digits (\d{4}
). The last capturing group is (-.*)
, i.e. the “-Name” part in your example. This group is # 4, since non-capturing groups are not counted.
In the replacement part, you simply string together the capturing groups 1 through 4 with the underscores you want.
Since the rule only matches the file names you described, it should do what you want. Please test first with a copies! And adjust the rule accordingly if the part after the date is not four digits…