Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Software > Calibre > Library Management

Notices

Reply
 
Thread Tools Search this Thread
Old 11-21-2022, 10:21 AM   #1
Gil_Bates
Member
Gil_Bates began at the beginning.
 
Posts: 17
Karma: 10
Join Date: Nov 2022
Device: Vivlio Touch Hd plus
Regex : How to catch authors separated with &

Hello I have a problem with Regex in search and replace, with multiple authors separated by & and their name and first name separated by coma

Suppose there are authors in Calibre library named in such way
Name_Auth1, First_Name_Auth1 & Name_Auth2, First_Name_Auth2
and I want to replace this with
FirstName Auth1 Name_Auth1 & FirstName_Auth2 Name Auth2
( concrete example : Herbert,Brian & Anderson,Kevin J. that I want to transform to Brian Herbert & Kevin J. Anderson )

1st problem inside search and replace checking zone, the & inside authors is shown as ::: in this way in our example :
Herbert,Brian ::: Anderson,Kevin J.

2nd Problem, impossible to match authors name parts
On a regex checking site https://regex101.com/ these regex works
(.*),(.*)\s:::\s(.*),(.*)
with ^(.*),(.*)\s:::\s(.*),(.*) it works too, and gives 4 groups with each part of name of each author, exactly what I need here
( it works also with real names with & and regex with & instead of ::
so it should work in Calibre too with "Replace by" set to
\2 \1 & \4 \3

But it doesn't work in Calibre.
Of course it doesn't work with
(.*),(.*)\s&\s(.*),(.*)
and even with \&. or with ^ at beginning too
If you know how to set this regex, I'll be very happy and grateful. Thanks a lot.
-----------------------French ----------------------------------------
Bonjour j'ai un problème avec l'utilisation d'expressions régulières dans le module Editer les données par lot - Chercher Remplacer
avec les auteurs multiples séparés par &
Supposer des auteurs nommés dans Calibre ainsi
NomAut1, PrénomAut1 & NomAut2, PrénomAut2
que je veux remplacer par
PrénomAut1 NomAut1 & PrénomAut2 NomAut2
( exemple concret : Herbert,Brian & Anderson,Kevin J.
que je veux transformer en Brian Herbert & Kevin J. Anderson )

1er problème : dans la zone de test de l'expression régulière, le & devient :::
Dans notre exemple on voit Herbert,Brian ::: Anderson,Kevin J.

2ème problème, impossible de sélectionner les parties de nom des auteur
Sur un site de test d'expressions régulières https://regex101.com/ ces expressions fonctionnent
(.*),(.*)\s:::\s(.*),(.*)
( ça marche aussi avec les noms écrits avec & et l'expression régulière avec & au lieu de ::: )
Avec ^(.*),(.*)\s:::\s(.*),(.*) ça marche aussi sur le site de test et cela donne 4 groupes qui sont les parties de noms d'auteur que je recherche,

Donc dans Calibre cela devrait marcher en écrivant dans la zone
Remplacer par
\2 \1 & \4 \3
Mais ça ne marche pas
Bien entendu ça ne marche pas avec
(.*),(.*)\s&\s(.*),(.*)
ni (.*),(.*)\s\&\s(.*),(.*)
etc..
Si vous connaissez le moyen de programmer cette expression régulière je vous en remercie vivement.

Encore merci à tous
Gil_Bates is offline   Reply With Quote
Old 11-21-2022, 01:02 PM   #2
un_pogaz
Chalut o/
un_pogaz understands the importance of being earnest.un_pogaz understands the importance of being earnest.un_pogaz understands the importance of being earnest.un_pogaz understands the importance of being earnest.un_pogaz understands the importance of being earnest.un_pogaz understands the importance of being earnest.un_pogaz understands the importance of being earnest.un_pogaz understands the importance of being earnest.un_pogaz understands the importance of being earnest.un_pogaz understands the importance of being earnest.un_pogaz understands the importance of being earnest.
 
un_pogaz's Avatar
 
Posts: 439
Karma: 145424
Join Date: Dec 2017
Device: Kobo
Chalut

To switch "Lastname,Firstname" to "Firstname Lastname", it's strangely easier than you think. A simple "([^,&]+),([^,&]+)" => "\2 \1" is enough.

For "Bloodthorne,Ralts & Lastname,Firstname", the result will be "Ralts Bloodthorne&Firstname Lastname" (Calibre will automatically transform it into a valid format "Ralts Bloodthorne & Firstname Lastname"). No need to worry about the ampersand, it seems to work.

And if you haven't already done, I advise you to use the Mass Search/Replace plugin which will allow you to quickly launch various saved operations.

Français:
Spoiler:
Pour intervertir "Nom,Prénon" vers "Prénom Nom", s'est bizarrement plus simple qu'on ne le croit. Un simple "([^,&]+),([^,&]+)" => "\2 \1" suffit.

Pour "Bloodthorne,Ralts & Nom,Prénon", le résultat sera "Ralts Bloodthorne&Prénom Nom" (Calibre le transformera automatiquement en format valide "Ralts Bloodthorne & Prénon Nom"). Pas besoin de s'occuper de l'éperluette, apparemment ça passe.

Et si s'est pas déjà fait je te conseil le plugin Mass Search/Replace qui te permettra de lancé rapidement diverse opérations sauvegardé.
un_pogaz is offline   Reply With Quote
Advert
Old 11-21-2022, 03:36 PM   #3
theducks
Well trained by Cats
theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.
 
theducks's Avatar
 
Posts: 31,059
Karma: 60358908
Join Date: Aug 2009
Location: The Central Coast of California
Device: Kobo Libra2,Kobo Aura2v1, K4NT(Fixed: New Bat.), Galaxy Tab A
Even simpler: Use the Quality Check Plugin: FIX section
to adjust all selected books

Also note: Run that PI to FIND Metadata with those errors FIRST
I also standardize Author Initials this way

BTW It will not find-fix Jan & Bob Smith, ya gotta add a Smith to Jan's part
theducks is online now   Reply With Quote
Old 11-22-2022, 02:38 AM   #4
Gil_Bates
Member
Gil_Bates began at the beginning.
 
Posts: 17
Karma: 10
Join Date: Nov 2022
Device: Vivlio Touch Hd plus
Thanks a lot. It works great !

Thanks a lot un_pogaz
your regex is smart and works !!
I was too newbie in regex to think this way so this answer was also a good teaching. )

Quote:
Originally Posted by un_pogaz View Post
Chalut

To switch "Lastname,Firstname" to "Firstname Lastname", it's strangely easier than you think. A simple "([^,&]+),([^,&]+)" => "\2 \1" is enough.

For "Bloodthorne,Ralts & Lastname,Firstname", the result will be "Ralts Bloodthorne&Firstname Lastname" (Calibre will automatically transform it into a valid format "Ralts Bloodthorne & Firstname Lastname"). No need to worry about the ampersand, it seems to work.

And if you haven't already done, I advise you to use the Mass Search/Replace plugin which will allow you to quickly launch various saved operations.

Français:
Spoiler:
Pour intervertir "Nom,Prénon" vers "Prénom Nom", s'est bizarrement plus simple qu'on ne le croit. Un simple "([^,&]+),([^,&]+)" => "\2 \1" suffit.

Pour "Bloodthorne,Ralts & Nom,Prénon", le résultat sera "Ralts Bloodthorne&Prénom Nom" (Calibre le transformera automatiquement en format valide "Ralts Bloodthorne & Prénon Nom"). Pas besoin de s'occuper de l'éperluette, apparemment ça passe.

Et si s'est pas déjà fait je te conseil le plugin Mass Search/Replace qui te permettra de lancé rapidement diverse opérations sauvegardé.
Gil_Bates is offline   Reply With Quote
Old 11-22-2022, 02:40 AM   #5
Gil_Bates
Member
Gil_Bates began at the beginning.
 
Posts: 17
Karma: 10
Join Date: Nov 2022
Device: Vivlio Touch Hd plus
Thanks

Thank you for your answer theducks.

I will try this plugin and check its features

Quote:
Originally Posted by theducks View Post
Even simpler: Use the Quality Check Plugin: FIX section
to adjust all selected books

Also note: Run that PI to FIND Metadata with those errors FIRST
I also standardize Author Initials this way

BTW It will not find-fix Jan & Bob Smith, ya gotta add a Smith to Jan's part
Gil_Bates is offline   Reply With Quote
Advert
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Why PageEdit is separated software? un_pogaz Sigil 1 06-26-2019 09:55 AM
Tags separated by semi-colons Ravensknight Library Management 9 08-05-2016 09:28 PM
Some regex help to clean up authors LadyKate Library Management 4 04-15-2015 12:29 PM
Words get separated brianj6 Conversion 1 10-16-2011 10:08 PM
Why does the ebook cover got separated? black cat Ectaco jetBook 0 04-14-2010 12:36 PM


All times are GMT -4. The time now is 11:46 AM.


MobileRead.com is a privately owned, operated and funded community.