#1 2018-10-30 14:46

JanR
Member
Registered: 2018-10-30
Posts: 3

Swap name and surname, with 2 and 3 words

I have tried with Renamer - Rearrange to swap name and surname from booktitles conform den4b.com/forum/viewtopic.php?id=2239

Filename examples and required result:

Ann Patchett - Bel Canto.epub -> Patchett, Ann - Bel Canto.epub
Arthur C. Clarke - Childhood's end.epub -> Clarke, Arthur C. - Childhood's end.epub
Anne Frank - The diary of a young girl.epub -> Frank, Anne - The diary of a young girl.epub
Chris van Abkoude - Pietje Bell 1, Pietje Bell, of de lotgevallen van een ondeugende jongen.epub -> Abkoude, Chris van - Pietje Bell 1, Pietje Bell, of de lotgevallen van een ondeugende jongen.epub

I use delimiter (space) and pattern $2, $1 - $4 $5 $6 $7 $8 but results are wrong:
- if name is more than 2 syllables
- if title is longer than number of syllables (then spaces are added at the end)
How can I correctly swap name and surname, or should I change the pattern depending of the number of syllables?
Is there a pattern name for the whole title (everything between - and .epub)?

Offline

#2 2018-10-30 21:22

den4b
Administrator
From: den4b.com
Registered: 2006-04-06
Posts: 2,692

Re: Swap name and surname, with 2 and 3 words

It is not possible rearrange both the 2 words and the 3 words authors in a single execution, using the Rearrange rule. However, you could do that with two separate executions, or use a Regular Expressions rule instead.

To rearrange 3 words authors:

Rearrange: Split by exact pattern of delimiters " ", " ", " - ", New pattern "$3, $1 $2 - $4" (skip extension)

To rearrange 2 words authors:

Rearrange: Split by exact pattern of delimiters " ", " - ", New pattern "$2, $1 - $3" (skip extension)

You could add all files, use the 3 words rule first, unmark unchanged files, rename (only marked files), clear marked files, mark the remaining files and apply the 2 words rule to the remaining files.

Note: This method is prone to errors, especially if the filename contains multiple " - " delimiters.

It is better to use the following Regular Expressions rules:

1) Regular Expressions: Replace expression "\A([^-\s]+)\s+([^-\s]+)\s+([^-\s]+)\s+\-\s+" with "$3, $1 $2 - " (skip extension)
2) Regular Expressions: Replace expression "\A([^-\s]+)\s+([^-\s]+)\s+\-\s+" with "$2, $1 - " (skip extension)

These two rules above will handle both 2 words and 3 words authors in a single execution, and won't mess up files which don't follow the required pattern, e.g. 4 words authors.

renamer-rearrange-2-and-3-word-authors.png

Offline

#3 2018-10-31 00:46

eR@SeR
Senior Member
From: Земун, Србија
Registered: 2008-01-23
Posts: 310

Re: Swap name and surname, with 2 and 3 words

Hi JanR

You can use Rearrange rule examples provided by Denis or use Regular Expression ones.

I think that I've found a pattern to get desired results using one Regular expression rule so you can try and check.

Two or more words for author:

1) Regular Expressions: Replace expression "^(([^ ]+ )*[^ ]+) ([^ ]+) - (.+)" with "$3, $1 - $4" (skip extension)

Two or three words for author but not four and more:

1) Regular Expressions: Replace expression "^(([^ ]+ )?[^ ]+) ([^ ]+) - (.+)" with "$3, $1 - $4" (skip extension)


TRUTH, FREEDOM, JUSTICE and FATHERLAND are the highest morale values which human is born, lives and dies for!

Offline

#4 2018-10-31 16:47

JanR
Member
Registered: 2018-10-30
Posts: 3

Re: Swap name and surname, with 2 and 3 words

You helped me a lot in learning the regex, so I thank you both. I am trying to learn more about it, but it is hard. How should the regex look to convert these examples (Title - Christianname Surname) to 'Surname, Christianname(s) - Title':
Divine Misdemeanors - Laurell K. Hamilton.epub -> Hamilton, Laurell K. - Divine Misdemeanors
Dracula - Bram Stoker.epub -> Stoker, Bram - Dracula
Dress Your Family in Corduroy and Denim - David Sedaris.epub -> Sedaris, David - Dress Your Family in Corduroy and Denim
Pietje Bell 1, Pietje Bell, of de lotgevallen van een ondeugende jongen - Chris van Abkoude.epub -> Abkoude, Chris van - Pietje Bell 1, Pietje Bell, of de lotgevallen van een ondeugende jongen

Jan

Offline

#5 2018-10-31 23:49

eR@SeR
Senior Member
From: Земун, Србија
Registered: 2008-01-23
Posts: 310

Re: Swap name and surname, with 2 and 3 words

JanR wrote:

I am trying to learn more about it, but it is hard.

Yes, they are hard to learn and to understand but not impossible. Here are some good websites to start learn them:

https://www.regular-expressions.info
https://regexone.com

JanR wrote:

How should the regex look to convert these examples (Title - Christianname Surname)

Try this one:

1) Regular Expressions: Replace expression "(.+) - (([^ ]+ ?)* )([^ ]+)" with "$4, $2- $1" (skip extension)


TRUTH, FREEDOM, JUSTICE and FATHERLAND are the highest morale values which human is born, lives and dies for!

Offline

#6 2018-11-01 12:48

JanR
Member
Registered: 2018-10-30
Posts: 3

Re: Swap name and surname, with 2 and 3 words

This is great for >95%. Even with dutch preposition names (like Yvanka van der Zwaan or A.F.Th. van der Heijden). Only when more authors or missing christian name it does not work, which is fully acceptable!
Also thanks for the regex learning links.
Jan

Offline

Board footer

Powered by FluxBB