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 07-12-2014, 12:48 PM   #1
DeepSeaDiver
Junior Member
DeepSeaDiver began at the beginning.
 
Posts: 3
Karma: 10
Join Date: Jul 2014
Device: Kindle Paperwhite2
Bulk metadata edit dialog: Use of regular expressions - how to?

Hi there!

I would need a hint how to insert a text at the beginning of the title field in the search and replace tab of the bulk metadata edit dialog.

I am somehow as bit lost with the documentation for regular expressions and don´t get this to work.

Here is an example of what I try:

Text to insert: "Hero´s name - "

Titles:
Adventure on the hill
Adventure at seaside
Adventure in the living room

Desired result:
Hero´s name - Adventure on the hill
Hero´s name - Adventure at seaside
Hero´s name - Adventure in the living room


Optionally (or better: perfect), it would be cool to copy the content of the series field including index number and insert ist at position of Hero´s Name.
Hero´s name [1] - Adventure on the hill
Hero´s name [2] - Adventure at seaside
Hero´s name [3] - Adventure in the living room

This would be the easiest way and acoording to the Calibre manual it should work.

Quote:
"Finally, in regular expression mode you can copy values from one field to another. Simply make the source and destination field different. The copy can replace the destination field, prepend to the field (add to the front), or append to the field (add at the end)."
I am really missing some more practical examples in the regular expression area of the manual. The functions seem to be very powerful but documentation is a bit tricky to read, at least for me (non native English speaking).

Has somebody done this already and could possibly help me out?


Regards, Olli
DeepSeaDiver is offline   Reply With Quote
Old 07-12-2014, 01:18 PM   #2
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: 30,944
Karma: 60358908
Join Date: Aug 2009
Location: The Central Coast of California
Device: Kobo Libra2,Kobo Aura2v1, K4NT(Fixed: New Bat.), Galaxy Tab A
Olli
You should not normally code Series info in the Title Name within the library
Use the Series field: Heros name [index]

When sending to a device use a Template:

{series} [{series_index}] - {title}
theducks is offline   Reply With Quote
Advert
Old 07-12-2014, 07:15 PM   #3
BetterRed
null operator (he/him)
BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.
 
Posts: 21,662
Karma: 29711016
Join Date: Mar 2012
Location: Sydney Australia
Device: none
Quote:
Originally Posted by theducks View Post
Olli
You should not normally code Series info in the Title Name within the library
Use the Series field: Heros name [index]

When sending to a device use a Template:

{series} [{series_index}] - {title}
- if you're pre-pending series for sorting the book list, then you might want to consider using this plugin - [GUI Plugin] View Manager

BR
BetterRed is offline   Reply With Quote
Old 07-13-2014, 06:15 AM   #4
DeepSeaDiver
Junior Member
DeepSeaDiver began at the beginning.
 
Posts: 3
Karma: 10
Join Date: Jul 2014
Device: Kindle Paperwhite2
Thank you both for your good advices!

I´ll give the pugin a try and agree, that the usual way is to use the Series column. I do so usually as well inside the library.

However sometimes there is wrong or unsufficient metadata which is needed to be changes for several titles (or other fields) in a row, so I still would like to learn more about the usage of regular expression in the bulk search and replace dialog.

Somehow I am only able to use this dialog in the "standard" way by replacing strings, but this requires somthing common in the title fields. For total different titles, there must be a way to use the complete title string in a variable in the search field and use this full string in the replace field with a addition or change.

If there is a workshop or so for this topic I would be thankful.

Please see this as a technical question, not as a question of intended usage of particular fields.

Thanks and regards,
Olli
DeepSeaDiver is offline   Reply With Quote
Old 07-13-2014, 08:26 AM   #5
Adoby
Handy Elephant
Adoby ought to be getting tired of karma fortunes by now.Adoby ought to be getting tired of karma fortunes by now.Adoby ought to be getting tired of karma fortunes by now.Adoby ought to be getting tired of karma fortunes by now.Adoby ought to be getting tired of karma fortunes by now.Adoby ought to be getting tired of karma fortunes by now.Adoby ought to be getting tired of karma fortunes by now.Adoby ought to be getting tired of karma fortunes by now.Adoby ought to be getting tired of karma fortunes by now.Adoby ought to be getting tired of karma fortunes by now.Adoby ought to be getting tired of karma fortunes by now.
 
Adoby's Avatar
 
Posts: 1,737
Karma: 26785684
Join Date: Dec 2009
Location: Southern Sweden, far out in the quiet woods
Device: Samsung Galaxy Tab S8 Ultra
There are two possible problems. The calibre interface and the syntax of regular expressions. If you don't already know regular expressions, then I would suggest that is where you should start. There are books and whole websites about it. And also several posts here that tries to explain specific regexp search and replaces.

The interface is simple and doesn't differ from common practice. You create a regexp to match a field, with parentheses to be able to reference parts, and replace with a string that may include references to the parts designated with parentheses.

I assume that you have read what the manual has to say about it:

http://manual.calibre-ebook.com/regexp.html

Last edited by Adoby; 07-13-2014 at 08:32 AM.
Adoby is offline   Reply With Quote
Advert
Old 07-13-2014, 10:19 AM   #6
eschwartz
Ex-Helpdesk Junkie
eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.
 
eschwartz's Avatar
 
Posts: 19,421
Karma: 85400180
Join Date: Nov 2012
Location: The Beaten Path, USA, Roundworld, This Side of Infinity
Device: Kindle Touch fw5.3.7 (Wifi only)
I found this website to be very helpful in learning regex: http://regular-expressions.info
eschwartz is offline   Reply With Quote
Old 07-13-2014, 05:54 PM   #7
BetterRed
null operator (he/him)
BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.
 
Posts: 21,662
Karma: 29711016
Join Date: Mar 2012
Location: Sydney Australia
Device: none
This one has some useful examples ==>> Regular expression operations — Python v2.7.8

BR
BetterRed is offline   Reply With Quote
Old 07-14-2014, 07:04 AM   #8
DeepSeaDiver
Junior Member
DeepSeaDiver began at the beginning.
 
Posts: 3
Karma: 10
Join Date: Jul 2014
Device: Kindle Paperwhite2
Thanks to all, the links have been very useful!

Just in case somebody has the same problem or needs, here is my solution.

Most important: In the search and replace dialog, change search mode from "Character match" to "Regular Expression". I stumbled exactly over this point at the beginning as I thought, Calibre would recognize the RegEx automatically by its syntax, like my file manager does. No wonder, that nothing I tried in the beginning worked!


Inserting series info into the title field:
Works for mixed titles with and without filled series fields:

Search field: {template}
Template: {series} {series_index:0>2s|| - } {title}
Search for: (.*)
Replace with: \1
Destination field: title

If the series contains more than 99 books, you might want to replace the "2s" in the template by "3s".
Result will be 001 insted of 01 for the first book.

Output format will be normally Series-name 01 - Title
If someone prefers the format Series-name 01: Title
use instead:
Template: {series} {series_index:0>2s||: } {title}


Opposite way: Moving series name and index from title field to series fields.
The RegEx below works for these title formats:

Hero´s name 001 - Adventure on the hill
Hero´s name 2 - Adventure at seaside
Hero´s name 4: Adventure in the swamp

Result should be:

TITLE fields
Adventure on the hill
Adventure at seaside
Adventure in the swamp

SERIES fields
Hero´s name [1]
Hero´s name [2]
Hero´s name [4]


Step 1 - Copies series name name to series field
Search field: title
Search for: (.*?) (\d+)(: | - ).*
Replace with: \1
Destination field: series

Step 2 (Optional) - Copies series index to series_index field. Use, if the series is not complete (missing intermittend titles). Not needed for complete series, as Calibre can set the index automatically ascending.
Search field: title
Search for: (.*?) (\d+)(: | - ).*
Replace with: \2
Destination field: series_index


Step 3 - Deletes complete series infto from title
Search field: title
Search for: .*?(: | - )
Replace with:
Destination field: title or blank

Note: Leave "Replace with" empty (no space).



One more: Adding a note behind a set of titles:

Search field: title
Search for: (.*)
Replace with: \1 (my note)
Destination field: title or blank


As is is stated in the Calibre manual, please use these with caution and make sure that you always select the correct search and destination fields! However, I tested the searches above in both directions and with different files, worked fine for me and I saved the searches for quick access.


Regards, Olli
DeepSeaDiver is offline   Reply With Quote
Old 07-14-2014, 08:27 AM   #9
DoctorOhh
US Navy, Retired
DoctorOhh ought to be getting tired of karma fortunes by now.DoctorOhh ought to be getting tired of karma fortunes by now.DoctorOhh ought to be getting tired of karma fortunes by now.DoctorOhh ought to be getting tired of karma fortunes by now.DoctorOhh ought to be getting tired of karma fortunes by now.DoctorOhh ought to be getting tired of karma fortunes by now.DoctorOhh ought to be getting tired of karma fortunes by now.DoctorOhh ought to be getting tired of karma fortunes by now.DoctorOhh ought to be getting tired of karma fortunes by now.DoctorOhh ought to be getting tired of karma fortunes by now.DoctorOhh ought to be getting tired of karma fortunes by now.
 
DoctorOhh's Avatar
 
Posts: 9,895
Karma: 13806776
Join Date: Feb 2009
Location: North Carolina
Device: Icarus Illumina XL HD, Kindle PaperWhite SE 11th Gen
Thanks for sharing. I'm glad you got it sorted out to your satisfaction.

Quote:
Originally Posted by DeepSeaDiver View Post
Just in case somebody has the same problem or needs, here is my solution.
For anyone considering this avenue, as a general rule cluttering the Title field with anything but the Title is not advised.

If the goal is to ensure the series info in the Title field so it is reflected on the device, calibre has Metadata plugboards to insert whatever you want into the title field on the fly as the book is sent to the device.

If the goal is to sort your calibre library you can set a default sort and how many columns deep you wish to be able to sort the GUI by going to Preferences - Tweaks and setting the following tweaks:

# Specify columns to sort the booklist by on startup

example
Quote:
sort_columns_at_startup = [('authors', 0), ('series', 0), ('title', 0)]
# Set the maximum number of sort 'levels'

example
Quote:
maximum_resort_levels = 5
There are many other tweaks in that area that might interest folks. Read all of the tweaks here in the calibre manual.

Last edited by DoctorOhh; 07-14-2014 at 08:30 AM.
DoctorOhh is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Open file option from 'Edit Metadata' dialog box crackhammer Library Management 1 12-04-2013 04:39 PM
remove series in edit metadata dialog speakingtohe Conversion 2 04-01-2012 12:19 PM
Metadata from filename (regular expressions) geronimo72 Library Management 2 03-05-2012 04:14 PM
Could use a bit of help with regular expressions to edit books on conversion Flammy Conversion 3 12-29-2011 10:29 AM
Minor bug: tab order on bulk edit dialog in 0.7.23 kiwidude Calibre 1 10-11-2010 11:45 AM


All times are GMT -4. The time now is 11:34 PM.


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