Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Software > Calibre > Editor

Notices

Reply
 
Thread Tools Search this Thread
Old 03-13-2017, 01:36 PM   #1
calibre-ak-4711
Junior Member
calibre-ak-4711 knows what time it iscalibre-ak-4711 knows what time it iscalibre-ak-4711 knows what time it iscalibre-ak-4711 knows what time it iscalibre-ak-4711 knows what time it iscalibre-ak-4711 knows what time it iscalibre-ak-4711 knows what time it iscalibre-ak-4711 knows what time it iscalibre-ak-4711 knows what time it iscalibre-ak-4711 knows what time it iscalibre-ak-4711 knows what time it is
 
Posts: 6
Karma: 2480
Join Date: May 2015
Device: none
Rechenfunktion mit RegEx

Hello friends,

I need your help: I ​​edit with the Sigil editor an epub with about 3000 footnotes.
I must implement these:

Search: (<sup>)(\d+)(</sup>)
Replace <a href="Anm.xhtml#\2+47"><sup id = "n\2+47">[\2+47]</sup></a>
--- The footnote found is intended to be e.g. always add 47! ---
Result: <a href="Anm.xhtml#253"><sup id="n253">[253]</sup></a>

With RegEx, this is not possible, but I am on the net to the option:
Function Mode for Search & Replace in the Editot of the new internal Caliber editor. Here, a RegEx term can be extended by a function using Python.

Since I have never programmed with Python and would not want to learn it at 72 years, I ask you to help me solve my problem.

MfG Andreas

Last edited by calibre-ak-4711; 03-14-2017 at 03:05 PM. Reason: Google Translate
calibre-ak-4711 is offline   Reply With Quote
Old 03-15-2017, 12:37 PM   #2
Thom*
The Fumbler
Thom* began at the beginning.
 
Posts: 66
Karma: 10
Join Date: Jun 2015
Device: android 4.2/fbreader
Simple math for Regex

The following Regex-Function will add 47 to any number between <sup> and </sup>. You can then use normal Regex to make any other changes that you desire.

In the Find box put "<sup>(\d+)</sup>" without the quotes.

In the Function box put "Add numbers" again without the quotes.

The code required for "Add numbers" is as follows:
Code:
import regex
from calibre import replace_entities
from calibre import prepare_string_for_xml                  
                        
def replace(match, number, file_name, metadata, dictionaries, data, functions, *args, **kwargs):
    
    return ('<sup>' + str(47 + int(match.group(1))) + '</sup>')
Also, it should be noted that 72 is not too old to learn new things.
Thom* is offline   Reply With Quote
Advert
Old 03-15-2017, 02:34 PM   #3
calibre-ak-4711
Junior Member
calibre-ak-4711 knows what time it iscalibre-ak-4711 knows what time it iscalibre-ak-4711 knows what time it iscalibre-ak-4711 knows what time it iscalibre-ak-4711 knows what time it iscalibre-ak-4711 knows what time it iscalibre-ak-4711 knows what time it iscalibre-ak-4711 knows what time it iscalibre-ak-4711 knows what time it iscalibre-ak-4711 knows what time it iscalibre-ak-4711 knows what time it is
 
Posts: 6
Karma: 2480
Join Date: May 2015
Device: none
Simple math for Regex

Hello Thom,
thank you for your quick help!
Your function works with INT:
Return ('<sup>' + str (33 + int (match.group (1))) + '</ sup>')
But not with LONG
Return ('<sup>' + str (long(293) + long (match.group (1))) + '</ sup>')
I hope you have a solution for this.

PS: if you are over 70 years old, you should use your limited time for food, drink and pretty women!

MfG
Andreas

Last edited by calibre-ak-4711; 03-15-2017 at 03:21 PM.
calibre-ak-4711 is offline   Reply With Quote
Old 03-15-2017, 03:40 PM   #4
Thom*
The Fumbler
Thom* began at the beginning.
 
Posts: 66
Karma: 10
Join Date: Jun 2015
Device: android 4.2/fbreader
I have no problem using either int or long data types to make this function work regardless of the size of the number. Is it possible that you are using an older version of Calibre'? I don't know what the problem is.

Regarding septuagenarians, my mistake, you are absolutely correct.
Thom* is offline   Reply With Quote
Old 03-15-2017, 04:30 PM   #5
calibre-ak-4711
Junior Member
calibre-ak-4711 knows what time it iscalibre-ak-4711 knows what time it iscalibre-ak-4711 knows what time it iscalibre-ak-4711 knows what time it iscalibre-ak-4711 knows what time it iscalibre-ak-4711 knows what time it iscalibre-ak-4711 knows what time it iscalibre-ak-4711 knows what time it iscalibre-ak-4711 knows what time it iscalibre-ak-4711 knows what time it iscalibre-ak-4711 knows what time it is
 
Posts: 6
Karma: 2480
Join Date: May 2015
Device: none
Simple math for Regex

Hello Thom,

SORRY: I searched: (<sup>)(\d+)(</sup>) instead of <sup>(\d+)</sup> !!!

Thanks again

MfG
Andreas

Last edited by calibre-ak-4711; 03-15-2017 at 05:37 PM.
calibre-ak-4711 is offline   Reply With Quote
Advert
Old 03-15-2017, 05:44 PM   #6
Thom*
The Fumbler
Thom* began at the beginning.
 
Posts: 66
Karma: 10
Join Date: Jun 2015
Device: android 4.2/fbreader
Also, the space in </ sup> might be problematic.
Thom* is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Regex help please BookJunkieLI Calibre 3 07-01-2014 03:18 PM
Need help for a regex wobohohoho Sigil 4 01-02-2013 04:42 AM
Sync mit Handy etc. auch mit Nicht-Amazon-Büchern möglich! Wurstbrot Amazon Kindle 14 03-28-2012 09:29 AM
Regex Gunnerp245 Conversion 5 03-05-2012 04:15 PM
360 mit 15.3: Ansicht der ganzen Seite mit Zoom-Rahmen mh445 PocketBook 0 01-03-2011 04:53 PM


All times are GMT -4. The time now is 09:32 PM.


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