To answer the question of your post #1, you can try the following regex:
Code:
"chapter(\d+)[^>]+>\K(\d+)
with the following function:
Code:
def replace(match, number, file_name, metadata, dictionaries, data, functions, *args, **kwargs):
if not data :
data['chapter'] = 'Dummy'
if data['chapter'] == match.group(1):
data['note_number'] += 1
else:
data['chapter'] = match.group(1)
data['note_number'] = 1
return str(data['note_number'])
We start at 1. As long as the chapter number does not change, we increase the note number by 1 before making the '
return'. When the chapter number changes, we start again from 1.
You can do a previous count (ctrl + n in standard searches), but you have to execute "
replace all", then "
see what have changed", because the function uses the persistent dic
data. You have to start at the beginning of the ebook.
For your message #3, you can try the same function, but with the following regex (because of the brackets). I understood that the notes are grouped by chapter. That's it ? If not, we will have to modify the function and use "
file_name" to note the change of xhtml file instead of the file number in
href selected by the regex in
match.group(1).
Code:
"chapter(\d+)[^\[]+\[\K(\d+)
Start at the beginning of the ebook.
"
replace all", then "
see what have changed".