![]() |
#1 |
Member
![]() 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(.*),(.*) If you know how to set this regex, I'll be very happy and grateful. Thanks a lot.and even with \&. or with ^ at beginning too -----------------------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 |
![]() |
![]() |
![]() |
#2 |
Chalut o/
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() 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:
|
![]() |
![]() |
Advert | |
|
![]() |
#3 |
Well trained by Cats
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() 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 |
![]() |
![]() |
![]() |
#4 | |
Member
![]() 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:
|
|
![]() |
![]() |
![]() |
#5 | |
Member
![]() 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:
|
|
![]() |
![]() |
Advert | |
|
![]() |
|
![]() |
||||
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 |