Move name part via regex

Advanced Renamer forum
#1 : 30/01-23 00:35
Gernot
Gernot
Posts: 2
Hi all,

I've just tried AR to solve a specific problem.

The task:
I have years of photos saved with the date somewhere in the middle of the file name, e.g. ...[20150129]...JPG . To match my current naming convention I want to move this part to the front.

The problem:
I'd thought the move method would get me there, but not as I expected.
I defined the starting point with \s(?=[^\[\s]*\[) (white space before the [ ) -> works.
Target is ^ -> works.
What doesn't work is a regular expression as pattern length. I tried \[.+\] which should do the trick, but no dice, no reaction at all. It does work with numbers, though, which solves my problem. But why is AR ignoring my regex there?


30/01-23 00:35
#2 : 30/01-23 10:45
David Lee
David Lee
Posts: 1125
You are misinterpreting the way that regex work in the Move method.

The text string to be moved starts with the character following the beginning of the selection defined by "Move from:" and ends with the character preceding the beginning of the selection defined by "Move count:"

Thus, in your example...
Move from: \[
Move count: \]
would move the contents of the brackets (ie the date).

So your solution (assuming there are spaces both before and after the brackets) could be...

Move from: \s(?=\[)
Move count: \]\s\K
Move to: ^

Note that the "Move count:" regex is a workaround since "lookbehind" is not available in PCRE. "\K" is an instruction to exclude the preceding match from the final selection and so moves the selection point to the character following the white space.

An alternative solution would be to use a Replace method:

Replace: (.*)(\[.*\]\s)
with: \2\1
Use regular expressions


30/01-23 10:45 - edited 30/01-23 17:25
#3 : 01/02-23 04:04
Gernot
Gernot
Posts: 2
Reply to #2:
This works like a charme now, thanks a lot!
I thought I might have something backwards there. Could this be added to the user guide linked under the question mark? Since count normally serves as the length of the content to be moved, I assumed this length would have to be derived from the regular expression. I may have overlooked it, but couldn't find any better explanation.

Cheers!


01/02-23 04:04