View Single Post
Old 09-08-2026, 11:33 PM   #1
natruok
Junior Member
natruok began at the beginning.
 
Posts: 6
Karma: 10
Join Date: Jul 2026
Device: none
Regex search & replace giving inconsistent results when pulling from "Path" field

I'm trying to pull the exact name of all files via the "Path" field, since Calibre handles special characters in the title differently on export, and there doesn't seem to be an option to directly export a list of the Path in the export catalogue option.

Whenever I do this, the title case of the words isn't always consistent for certain files, and since epub files are case-sensitive, it doesn't identify the file when the name doesn't match exactly.

I've tried pulling using the following templates in regex search and replace:
Code:
program:
p = $path;
re(p, '^.*/(.+)\s\([0-9]+\)','\1')
Code:
program:
p = $path;
p = re(p,".+\/","");
p = re(p,"\s\([0-9]+\)$","");
Code:
python:
import re
def evaluate(book, context):

	p = book.get('path')
	p = re.search('(?<=./).+(?=\s\([0-9]+\))',p)
	return p.group(0)
I can't identify which files/why certain ones have issues, but what happens is:
  1. In the template box, it will show appropriately what I expect the result to be
  2. When I'm outside the template box, I get the error "S/R TEMPLATE ERROR Interpreter: Unknown field 'path' - line number #"
  3. After I run the search and replace, it will create a result that is either correct or incorrect — in this specific case with a one-word title, the first letter will be either capitalized or not; in the case of multi-word titles (can't find an exact example right now), the original title & path might be in Title Case, but the result will be either Title Case or only first letter of the entire title capitalized
  4. Each time I run the search and replace, when only one file is selected, it will "refresh" all the other results that fall under this same error. So when there are multiple errors, after I've fixed one, when I go to fix another, it will cause the error in the earlier one again.

It doesn't only occur with cases where I have duplicate titles, but it's easiest to demonstrate with that.

In the screenshot, the first time I run any of the searches above, it will show the correct "Amortentia", which is capitalized. Then if I preview it for the second line, it will show the correct "amortentia" in lower case for the second file, and after I run the search and replace, it will change both of them to "amortentia". And then if I go back to try and change the first one, it will again change both to "Amortentia".

I am running this on my entire library, so the results continue to fluctuate until the library is done.

Is there something that's wrong with my regex searches, or the way the Path column is handled?

In the image, the first Path column is the default calibre column, and the second Path column is custom column where I've run the search and replace.
Attached Thumbnails
Click image for larger version

Name:	Screenshot 2026-09-08 at 20.04.33.png
Views:	9
Size:	41.3 KB
ID:	225794  
natruok is offline   Reply With Quote