View Single Post
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