Quote:
Originally Posted by Doitsu
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.