Need some help.

Advanced Renamer forum
#1 : 01/03-20 19:09
James
James
Posts: 2
Hello! I was trying to create a swapping method, but can't seem to get it right with/without regular expressions. I'd really appreciate anyone's help.
There's basically 3 parts in a filename, id - name room - specialty.

Example filenames:
8946 - Andy Room J, Jean Room F - Sociology Student - Marketing Student.txt
2547 - Carol-Kaye Room A - Art Student.txt
9639 - Jimmy Room B, Travis Room H, Alex Room G - Art Student - Sociology Student - Marketing Student.txt
7834 - Serena Room A - Art Student - Chemistry Student.txt

Result I seek:
Sociology Student - Marketing Student - Andy Room J, Jean Room F - 8946.txt
Art Student - Carol-Kaye Room A - 2547.txt
Art Student - Art Student - Art Student - Jimmy Room B, Travis Room H, Alex Room G - 9639.txt
Art Student - Chemistry Student - Serena Room A - 7834.txt

Thanks in advance!


01/03-20 19:09
#2 : 02/03-20 11:01
David Lee
David Lee
Posts: 1125
Use Replace with (.*?) - (.*?) - (.*)
and replace with \3 - \2 - \1

You need to understand a feature of regular expressions not included in the User Guide...

By default the "*" quantifier is "greedy" and will match as many repetitions as possible - so that "(.*) - " will match all characters up to the last possible instance of " - ". Adding "?" (ie "(.*?) - ") will change the behaviour of "*" to "lazy" so that it will match as few repetitions as possible and the match will terminate at the first instance of " - ".

So for a case where a student has more than one speciality - eg "Jimmy Room B, Travis Room H, Alex Room G - Art Student - Sociology Student - Marketing Student"...

Regex (.*) - (.*) - (.*) would return:
Marketing Student - Sociology Student - 9639 - Jimmy Room B, Travis Room H, Alex Room G - Art Student

but (.*?) - (.*?) - (.*) will return :
Art Student - Sociology Student - Marketing Student - Jimmy Room B, Travis Room H, Alex Room G - 9639

Note that you still want the final sub-expression to be greedy, such that it will capture all the rest of the filename, so do not add the "?" modifier.




02/03-20 11:01 - edited 02/03-20 11:58
#3 : 08/03-20 13:18
James
James
Posts: 2
Reply to #2:
Big thanks!!!


08/03-20 13:18