Folder renaming challenge

Advanced Renamer forum
#1 : 20/10-18 00:25
Paul
Paul
Posts: 3
Hi guys,

I'm trying to get some folders renamed but can't wrap my head around it yet due to inexperience in the fine arts of advanced renaming :)
Any pointers or tips would be greatly appreciated!

Source folders:

txta.txtb.txtc...txtn.dddd.ddddt.txtd.txte.txtf...txtn-txtg
-> txta txtb txtc txtn [dddd]

Exceptions: when txta = A or when txta = The
-> txtb txtc txtn, txta [dddd]

Examples:
One.100.Days.2012.2054q.rem-BOOK
-> One 100 Days [2012]

The.Salesman.and.You.1972.4512j.lda-DRAFT
-> Salesman and You, The [1972]

A.Day.in.your.Life.1947.1020w.fge-PLAY
-> Day in your Life, A [1947]

Thanks!
Paul.


20/10-18 00:25
#2 : 21/10-18 22:48
Paul
Paul
Posts: 3
After some digging & lots of trial & error I was able to accomplish this with these 3 methods:

1: Replace
• TBR = (.+?)(\d{4})(.*)
• RPW = \1[\2]
• RGX = checked

2: Replace
• TBR = (^The\.|^A\.)(.*?)(\[\d{4}\])
• RPW = \2,.\1\3
• RGX = checked

3: List Replace
• TBR1 = ., RPW1 = .
• TBR2 = . RPW2 = " " (space without quotes)
• RGX = unchecked

Please let me know if there is a more elegant/simplified/efficient solution.

Thanks,
Paul.


21/10-18 22:48
#3 : 23/10-18 14:35
David Lee
David Lee
Posts: 1125
Reply to #2:

You can do it using just two methods if you add ? to the first sub-pattern in your step 2, so that zero or one repetitions of (^The.|^A.) are matched:

1: Replace (RegEx)
• TBR = ((^The\.|^A\.)?)(.+?)(\.?)(\d{4})(.*)
• RPW = \3, \1[\5]

2: List Replace
• TBR1 = . RPW1 = <space>
• TBR2 = ,<space>[ RPW2 = <space>[

Probably not worth the effort sorting it out - but it was a nice challenge!

There is an oddity here that I have seen before. I would have expected that the replace string in step 1 should be \2, \1[\4] but sub-pattern \2 is a repeat of \1.


23/10-18 14:35 - edited 23/10-18 15:02
#4 : 23/10-18 15:10
David Lee
David Lee
Posts: 1125
Reply to #3:

Solved the oddity: the extra pair of parentheses around the first sub-pattern is unnecessary.

(^The\.|^A\.|^An\.)?(.+?)(\.?)(\d{4})(.*) replaced with \2, \1[\4] works as expected.

I still don't know why ((^The\.|^A\.|^An\.)?) should return TWO identical sub-patterns though.


23/10-18 15:10
#5 : 24/10-18 08:54
Paul
Paul
Posts: 3
Reply to #4:

Hi David,

Thanks for your insights and help! Your solution is indeed more elegant & powerful.
Regex is indeed both incredible powerful but also quite intricate to get the hang of it.
Scratching the surface makes me realize the potential but also the pitfalls and headaches :)

Thanks again!
Cheers, Paul.


24/10-18 08:54 - edited 24/10-18 08:56