Moving last two words in filename

A swapping-ground for Regular Expression syntax

Moving last two words in filename

Postby Mysteron » Mon May 15, 2023 4:03 pm

I have been struggling to find a solution for moving the last two (or three) words to the second word position from a multi word filename i.e.

CD1 Dark side of the moon Pink Floyd
CD2 Heroes David Bowie
CD3 Animals Pink Floyd

to

CD1 Pink Floyd Dark side of the moon
CD2 David Bowie Heroes
CD3 Pink Floyd Animals

Any help would be greatly appreciated!

Thanks!
Mysteron
 
Posts: 2
Joined: Mon May 15, 2023 3:55 pm

Re: Moving last two words in filename

Postby therube » Mon May 15, 2023 5:36 pm

Not sure if this will do it or not, but test & see (if at least some is [somewhat] correct).
It would not work for something like: CD9 Psycho Circus KISS (& probably more gotcha's too).

1:RegEx
Code: Select all
Match:  (.*?)\s(.*)\s(.*)\s(.*)
Replace:  \1   -------   \3 --- \4   -------   \2

(dashes, spaces, are only there for readability)

match anything, non-greedy, up to a <sp> (1st. word, \1)
match anything, greedy, up to a <sp> (\2)
match next to last word (\3)
match last word (\4)
rearrange
therube
 
Posts: 1319
Joined: Mon Jan 18, 2016 6:23 pm

Re: Moving last two words in filename

Postby Mysteron » Wed May 17, 2023 10:43 am

Many thanks, that works.

I am still trying to get my head round Regular Expressions and your explanation of the solution really helped too. Cheers!
Mysteron
 
Posts: 2
Joined: Mon May 15, 2023 3:55 pm


Return to Regular Expressions


cron