View Single Post
Old 09-16-2015, 12:40 PM   #17
Thom*
The Fumbler
Thom* began at the beginning.
 
Posts: 66
Karma: 10
Join Date: Jun 2015
Device: android 4.2/fbreader
Another try

I was so inspired by davidfor's suggestion to use Regex-Funtion mode that I delved into it and wrote my first function. It was a challenge that I could not pass up. I do believe that it works just as you requested, so I might as well share it with you.

So:
- Begin by selecting "Regex-Function" in the search/replace panel.
- Leave the "All text files" selected.
- Make sure there are no files listed in the "Function:" box so that when you hit "Create/edit" a new file will be created.
- Click "Create/edit" and name the new file what you like (I named it "FixIt").
- Copy the following code to the body of the new file replacing anything that is there.
Code:
def replace(match, number, file_name, metadata, dictionaries, data, functions, *args, **kwargs):

    newid = ('<p id="id_' + (file_name [-10:-5:]) + ("000" + match.group(1)) [-3:] + '" class="calibre1"><sup class="calibre2">' + match.group(1) + '</sup>')

    return newid
- Check to be sure you have 0 spaces before "def replace", 4 spaces before "newid" and 4 spaces before "return".
- Click "OK" and you are ready to rock and roll.
- Use the search string that I provided you previously: <p class="calibre2"><sup class="calibre3">(.*?)</sup>
- Hit replace and you should be in business.
- It should do what you want to all files.

Please let me know if this works for you or what problems you encounter.

That was great fun, thanks for the challenge.
Thom* is offline   Reply With Quote