View Single Post
Old 03-22-2022, 09:02 PM   #58
The_book
Zealot
The_book began at the beginning.
 
Posts: 100
Karma: 10
Join Date: Aug 2019
Device: none
Quote:
Originally Posted by KevinH View Post
I also have a question about the value of the request to add python function replace? Who actually uses this feature in calibre to write their own python routines for anything else other than numbering things?

Things like changing case can already be done, and smart quotes conversion is better done in plugin settings.

As for numbering why could we not just include the match count as an additional subcapture pattern value allowing the user to reference it in any replacement. Or alternatively just create a plugin that does heading renumbering. A heading renumberer plugin would be the most flexible if you allow the a regex to determine what you are numbering.

What else are people actually using it for that would not be handled better by a plugin.

Having a general user write their own replacement functions in python, edit them, debug them, compile them to bytecode, add and delete them, etc is a lot of overhead and code bloat for just numbering things.

So is this still needed assuming we added a general renumbering plugin controlled by a regex?
I use it in there ways.
1. I use it to Print all matchs, then I can check do I need to improve my regex. I also use Set to combine the same matchs.
2. I use it in match some <span> tag. Maybe because I'm not very familiar with regular expressions, I can not find a good way to match the close tag in html like this.
<span><span class="..." style="..."><span><span></span></span><span></span></span></span>
So I match all, and parse it in Python.
3. I use it to match condition like class="1 2 3 4" class="3 5 2 1" class="2 6 1 3". They must have 1,2,3, but order is not imortant.
The_book is offline   Reply With Quote