02-11-2024, 03:37 PM | #1 |
Junior Member
Posts: 4
Karma: 10
Join Date: Feb 2024
Device: Kindle Paperwhite 4th Iteration (Gen. 10)
|
Use search and replace to add leading zeroes
I want to use search and replace on a bulk of files named "Chapter 1, Chapter 2... Chapter 100" to include leading zeroes so every file is 3 digit long: "Chapter 001, Chapter 002... Chapter100". If I enter "\d+" in the "Search for" field it detects the numbers but I don't know what to put in the "Replace with" field. \\n refers back to the number but how can i modify it conditionally?
|
02-11-2024, 04:46 PM | #2 |
Wizard
Posts: 1,103
Karma: 4911876
Join Date: Sep 2021
Location: Australia
Device: Kobo Libra 2
|
Where exactly are you trying to do this?
Is it in the Editor? Is it the xhtml files or the chapter headings in those files, or is it somewhere else? I am just not sure where you would see that in "Library Management". |
02-11-2024, 07:14 PM | #3 |
Junior Member
Posts: 4
Karma: 10
Join Date: Feb 2024
Device: Kindle Paperwhite 4th Iteration (Gen. 10)
|
In the virtual library selecting them all and clicking "Edit Metadata". Thought it was the right Channel because it has "managing metadata" in its description
|
02-11-2024, 07:31 PM | #4 |
Wizard
Posts: 1,103
Karma: 4911876
Join Date: Sep 2021
Location: Australia
Device: Kobo Libra 2
|
Maybe you can post a screenshot because I am not really understanding where you are seeing "Chapters" in the library listing.
|
02-11-2024, 07:33 PM | #5 |
Well trained by Cats
Posts: 29,809
Karma: 54830978
Join Date: Aug 2009
Location: The Central Coast of California
Device: Kobo Libra2,Kobo Aura2v1, K4NT(Fixed: New Bat.), Galaxy Tab A
|
The place is correct.
What we don't understand is WHY-WHERE this is to be done??? Numeric fields do not show leading 0's (integer>=1). 0.5 will show a single 0 Padding with 0 (or a space) is only valid for Text You can 'format' filename strings in the send to Disk (or device) template {series_index:0>5.2f} That is my template for series_index when included in a filename. 2 digits before the . and 2 after (the 5) |
02-11-2024, 07:48 PM | #6 | |
Junior Member
Posts: 4
Karma: 10
Join Date: Feb 2024
Device: Kindle Paperwhite 4th Iteration (Gen. 10)
|
Quote:
I want to merge all those epubs. But because sorting by "Title" it sorts digit after digit instead of the whole number I thought it would be the best to add leading zeroes so the chapters are in the right order (images are not shown for some reason https://imgur.com/a/an1SuqA, https://imgur.com/a/V5tn2Pd) |
|
02-11-2024, 11:31 PM | #7 |
null operator (he/him)
Posts: 20,575
Karma: 26954694
Join Date: Mar 2012
Location: Sydney Australia
Device: none
|
|
02-12-2024, 02:57 AM | #8 | |
Grand Sorcerer
Posts: 11,742
Karma: 6997045
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Quote:
the option Preferences / Behavior / Recognize numbers inside text when sorting. With the option unchecked: With the option checked: You can also use a bulk search & replace with source "template" to change the titles to have a fixed number of leading zeros This is complicated and error prone so I don't recommend it. The template would be something like this, assuming that the number always appears at the end and that it can be floating point: Code:
program: text = re($title, '^(.*?)[\d\.]*$', '\1'); digits = re($title, '.*?((\d+(?:\.\d*)?|\.\d+)).*?', '\1'); digits = format_number(digits, '08.2f'); title = text & digits |
|
02-12-2024, 03:38 AM | #9 | |
Junior Member
Posts: 4
Karma: 10
Join Date: Feb 2024
Device: Kindle Paperwhite 4th Iteration (Gen. 10)
|
Quote:
|
|
Tags |
calibre, template language |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Search and replace | Th0mC | Calibre | 2 | 11-07-2020 07:08 AM |
Regex in search problems (NOT Search&Replace; the search bar) | lairdb | Calibre | 3 | 03-15-2017 07:10 PM |
save multiple search/replace, or search/replace multiple ebooks | user743 | Editor | 12 | 04-12-2014 02:38 AM |
How to add leading zeros to the front of a series | peaceridge | Library Management | 4 | 11-18-2013 11:46 AM |
search and replace - drops blanks in replace ? | cybmole | Conversion | 10 | 03-13-2011 03:07 AM |