View Single Post
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