View Single Post
Old 03-01-2025, 10:46 AM   #65
KevinH
Sigil Developer
KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.
 
Posts: 8,894
Karma: 6120478
Join Date: Nov 2009
Device: many
Quote:
Originally Posted by Doitsu View Post
Could you please give an example for this?
Yes here is a very silly contrived example to sequentially number all of the words "the" in all xhtml spine order in all xhtml files.

Find: (?sm)\s(the)\s

Replace \F<numberthes>

Where the numberthes is the following replace function:

Code:
def replace(match, number, file_name, metadata, data):
	if match:
		return ' ' + match.group(1) + str(number) + ' '

Then you must use ReplaceAll not one by one replace as no number history is kept if not a finite set of replacements in a single down direction is knowable.

I just tried this and it worked as expected for me.

If you want more complicated numbering, then instead of using the "number" parameter, initialize your own variable called "mycount" as follows:

Code:
if number == 1:
    data['mycount'] = 1
    data['cur_file'] = file_name
Then add to "mycount whenever you want and reset it when a new value of file_name is used. So if you want to number only h1 or all h1|h2|h3 title strings, you do that in the Find regex and make sure to capture anything you need to build the output you want.

Last edited by KevinH; 03-01-2025 at 12:24 PM.
KevinH is offline   Reply With Quote