flipping names exchange swap move first last name, firstname

A swapping-ground for Regular Expression syntax

flipping Swap exchange parts filename dash hyphen minus

Postby Stefan » Sat May 04, 2013 9:15 am

FROM:
Song - Artist.mp3
Song Title - Artist.mp3
Song Title - Artist name.mp3

TO:
Artist - Song.mp3
Artist - Song Title.mp3
Artist name - Song Title.mp3

Rule:
Match everything till an space-hyphen-space and store it in ()-group 1,
then match the rest till the extension and store it in group 2.
At the replacement reorder the stored matches and reference to group 2 first by using \2,
then add an hyphen literally your self and add \1 to 'paste' what was matched in group 1.

DO:
RegEx(1)
Search: (.+) - (.+)
Replace: \2 - \1


"[ ] Include Ext." is unchecked.
"Options > Ignore... > File Extensions" is unchecked.
Select a few files in the Name column to see what happens in the NewName column.


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

Re: flipping names exchange swap move first last name, firstname

Postby psychopython » Mon May 01, 2017 4:04 am

Its an old post. But still... here you go

8)


filename1 - filename2
to
filename2 - filename1
https://www.youtube.com/watch?v=C58Odqe2q6s


Match: (.*) - (.*)
Replace: \2 - \1
psychopython
 
Posts: 1
Joined: Mon May 01, 2017 3:54 am

Re: flipping names exchange swap move first last name, firstname

Postby LuckyMenace » Mon Jul 09, 2018 1:43 am

Some of the solutions above kind of work except these kind of scenarios:
Aldron T. Smith
Jane Doe-Smith
Jim Darling Jr.

I've been trying to get the following results:
Smith, Aldron T.
Doe-Smith, Jane
Darling Jr., Jim

Is this even possible in one step?
LuckyMenace
 
Posts: 1
Joined: Mon Jul 09, 2018 1:39 am

Re: flipping names exchange swap move first last name, firstname

Postby Karaoketyd » Mon May 13, 2024 2:11 pm

I'm using this formula to swap a first and last name (John Doe to Doe, John)
Match: ^([A-Z][a-z]*) ([A-Z][a-z]*)(.*)
Replace: \2, \1\3
However, I found If I end up with a name like John McDoe It sees the Mc as a separate name and I end up with Mc, JohnDoe.
How would I fix this so McDoe ends up one name instead of two?

Thanks
Karaoketyd
 
Posts: 3
Joined: Mon May 13, 2024 2:05 pm

Re: flipping names exchange swap move first last name, firstname

Postby Luuk » Tue May 14, 2024 2:43 am

@Karaoketyd
Can change your 2nd [A-Z] ---> (?:Mc)?[A-Z]
Luuk
 
Posts: 722
Joined: Fri Feb 21, 2020 10:58 pm

Re: flipping names exchange swap move first last name, firstname

Postby Karaoketyd » Tue May 14, 2024 2:30 pm

I replace the code to this ^([A-Z][a-z]*) (?:Mc)?[A-Z] [a-z]*)(.*) but it prevented the name from changing. I'm trying to Change Scotty McCreery - Fall of Summer to McCreery, Scotty - Fall Of Summer
Karaoketyd
 
Posts: 3
Joined: Mon May 13, 2024 2:05 pm

Re: flipping names exchange swap move first last name, firstname

Postby Luuk » Tue May 14, 2024 8:18 pm

@Karaoketyd
Its because you changed ([A-Z] instead of [A-Z]
So it invents an illegal expression without having balanced parenthesis.
Luuk
 
Posts: 722
Joined: Fri Feb 21, 2020 10:58 pm

Re: flipping names exchange swap move first last name, firstname

Postby Karaoketyd » Thu May 16, 2024 1:02 am

Yes! Thanks for noticing that mistake. Works perfectly now. Thank You
Karaoketyd
 
Posts: 3
Joined: Mon May 13, 2024 2:05 pm

Previous

Return to Regular Expressions