Swap Last Two [or more] words of Filename.

Post any Bulk Rename Utility support requirements here. Open to all registered users.

Swap Last Two [or more] words of Filename.

Postby FOL » Sun Aug 28, 2011 1:32 am

Hi there,

Could someone help me switching the positioning of the last two words in a filename please... Ex:

< A book - Author, An
> A book - An Author

I've tried the RegEx code [which didn't change anything]:

RegEx(1)
MATCH: (.+), (.+)( - .+)
REPLACE: \2 \1\3

If possible, could someone please also help solving the same issue but with more than two words [3,4 or more words]... Ex:

< A book - Author, An Acclaimed And Noteworthy
> A book - An Acclaimed And Noteworthy Author
FOL
 
Posts: 1
Joined: Sun Aug 28, 2011 1:03 am

Re: Swap Last Two [or more] words of Filename.

Postby Stefan » Mon Aug 29, 2011 7:01 am

Hi FOL

you need to have one common pattern for all file names.
Our anchors will be SpaceDashSpace and the coma.

Let's try with
( 1: All signs till SpaceDashSpace, stored in group 1 )
( 2: one single word, stored in group 2 )( 3: an coma, which we will drop )
( 4: one space and the rest, stored in group 3 )

and replace by \1\3\2


FROM:
A book - Author, An
A book - Author, An Acclaimed And Noteworthy
TO:
A book - An Author
A book - An Acclaimed And Noteworthy Author

RegEx(1)
MATCH: (.+ - )(\w+),( .+)
REPLACE: \1\3\2


Please try and report back.

 
Stefan
 
Posts: 736
Joined: Fri Mar 11, 2005 7:46 pm
Location: Germany, EU

Re: Swap Last Two [or more] words of Filename.

Postby Dustydog » Wed Mar 23, 2016 3:43 am

( 1: All signs till SpaceDashSpace, stored in group 1 )
( 2: one single word, stored in group 2 )( 3: an coma, which we will drop )
( 4: one space and the rest, stored in group 3 )

and replace by \1\3\2


FROM:
A book - Author, An
A book - Author, An Acclaimed And Noteworthy
TO:
A book - An Author
A book - An Acclaimed And Noteworthy Author

RegEx(1)
MATCH: (.+ - )(\w+),( .+)
REPLACE: \1\3\2


I tried this exactly as listed, and it gave me the following (note two spaces after dash):

A book - AnAuthor
A book - An Acclaimed And NoteworthyAuthor

Your technique in general, though, is spot on, and I appreciate your time.

Lol, didn't notice the age of the thread - appreciate your time regardless of when you spent it.

***

For what it's worth this gives the correct result:

(.+ - )(\w+), (.+) | Doesn't matter if there's a space at the start of word 3 match.
\1\3 \2 | Add a space between \3 \2

(By the way, Notepad++ is an excellent (free) tool in which to test Regular Expressions - gives me the same results - so far.)
Dustydog
 
Posts: 11
Joined: Wed Mar 23, 2016 3:32 am


Return to BRU Support


cron