![]() |
#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?
|
![]() |
![]() |
![]() |
#2 |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 1,284
Karma: 6700678
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". |
![]() |
![]() |
Advert | |
|
![]() |
#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
|
![]() |
![]() |
![]() |
#4 |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 1,284
Karma: 6700678
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.
|
![]() |
![]() |
![]() |
#5 |
Well trained by Cats
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 30,274
Karma: 57979022
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) |
![]() |
![]() |
Advert | |
|
![]() |
#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) |
|
![]() |
![]() |
![]() |
#7 |
null operator (he/him)
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 20,854
Karma: 27620684
Join Date: Mar 2012
Location: Sydney Australia
Device: none
|
|
![]() |
![]() |
![]() |
#8 | |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 11,908
Karma: 7076137
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 |
|
![]() |
![]() |
![]() |
#9 | |
Junior Member
![]() Posts: 4
Karma: 10
Join Date: Feb 2024
Device: Kindle Paperwhite 4th Iteration (Gen. 10)
|
Quote:
|
|
![]() |
![]() |
![]() |
Tags |
calibre, template language |
|
![]() |
||||
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 |