Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Software > Calibre > Editor

Notices

Reply
 
Thread Tools Search this Thread
Old 08-02-2023, 11:05 PM   #1
MerlinMama
Evangelist
MerlinMama does all things with Zen-like beautyMerlinMama does all things with Zen-like beautyMerlinMama does all things with Zen-like beautyMerlinMama does all things with Zen-like beautyMerlinMama does all things with Zen-like beautyMerlinMama does all things with Zen-like beautyMerlinMama does all things with Zen-like beautyMerlinMama does all things with Zen-like beautyMerlinMama does all things with Zen-like beautyMerlinMama does all things with Zen-like beautyMerlinMama does all things with Zen-like beauty
 
MerlinMama's Avatar
 
Posts: 487
Karma: 32554
Join Date: May 2014
Location: Canada
Device: Kobo Libra Colour
Help with S&R RegEx Function

Something strange just happened. I was correcting some fanfics I just finished reading. I have a Saved Search that I use to modify my Last Read date on the cover page.

I did one of the fics, no problem. I closed the first fic, opened the second one, and it no longer works correctly. I have no clue.

On my cover page, the line is:

Spoiler:
<dt><b>Last Read:</b></dt><dd> 07/13/2020</dd><br/><br/>

I sometimes have nothing for the date, and sometimes I have N/A, depending on how old the fic is


The find portion of the saved search is:

Spoiler:
Code:
Last Read:</b></dt><dd>\K((<em>)?N/A(</em>)?| \d{1,2}/\d{2}/\d{4}| \d{1,2}-\d{2}-\d{4}|\s)


I use a Regex-Function for the replace portion of the saved search:

Spoiler:
Code:
def replace(match, number, file_name, metadata, dictionaries, data, functions, *args, **kwargs):
    from datetime import datetime
    return datetime.now().strftime(" %m/%d/%Y")


Now when I hit find on the saved search it only highlights the following section:

Spoiler:
<dt><b>Last Read:</b></dt><dd>


I want to be clear that I did not do any editing AT ALL in the saved search (even for another saved search).

I hope someone can clear this up for me.
MerlinMama is offline   Reply With Quote
Old 08-03-2023, 03:16 PM   #2
MerlinMama
Evangelist
MerlinMama does all things with Zen-like beautyMerlinMama does all things with Zen-like beautyMerlinMama does all things with Zen-like beautyMerlinMama does all things with Zen-like beautyMerlinMama does all things with Zen-like beautyMerlinMama does all things with Zen-like beautyMerlinMama does all things with Zen-like beautyMerlinMama does all things with Zen-like beautyMerlinMama does all things with Zen-like beautyMerlinMama does all things with Zen-like beautyMerlinMama does all things with Zen-like beauty
 
MerlinMama's Avatar
 
Posts: 487
Karma: 32554
Join Date: May 2014
Location: Canada
Device: Kobo Libra Colour
After fiddling around, I managed to get something workable. I would still like to know, if possible, why what I had stopped working so suddenly. I had set up the regex-function over a year ago in a basic form, but about 6 or so months ago, I changed the format on my cover page and added the '</dt><dd>' part only.

I had to remove '\K' from the find, and I changed the regex-function part to:

Spoiler:
Code:
def replace(match, number, file_name, metadata, dictionaries, data, functions, *args, **kwargs):
    from datetime import datetime
    return 'Last Read:</b></dt><dd>' + datetime.now().strftime(" %m/%d/%Y")

**I added the underline here to show what I added, it is not in the actual regex-function**

If there is a better way to accomplish this, any suggestions are welcome!
MerlinMama is offline   Reply With Quote
Advert
Old 08-16-2023, 12:16 PM   #3
lomkiri
Zealot
lomkiri ought to be getting tired of karma fortunes by now.lomkiri ought to be getting tired of karma fortunes by now.lomkiri ought to be getting tired of karma fortunes by now.lomkiri ought to be getting tired of karma fortunes by now.lomkiri ought to be getting tired of karma fortunes by now.lomkiri ought to be getting tired of karma fortunes by now.lomkiri ought to be getting tired of karma fortunes by now.lomkiri ought to be getting tired of karma fortunes by now.lomkiri ought to be getting tired of karma fortunes by now.lomkiri ought to be getting tired of karma fortunes by now.lomkiri ought to be getting tired of karma fortunes by now.
 
lomkiri's Avatar
 
Posts: 136
Karma: 1000102
Join Date: Jul 2021
Device: N/A
Quote:
Originally Posted by MerlinMama View Post
Now when I hit find on the saved search it only highlights the following section:

Spoiler:
<dt><b>Last Read:</b></dt><dd>
It's because you're searching upward. If you change the direction of the search (i.e. downward), it'll work as expected.
lomkiri is offline   Reply With Quote
Old 08-16-2023, 12:28 PM   #4
MerlinMama
Evangelist
MerlinMama does all things with Zen-like beautyMerlinMama does all things with Zen-like beautyMerlinMama does all things with Zen-like beautyMerlinMama does all things with Zen-like beautyMerlinMama does all things with Zen-like beautyMerlinMama does all things with Zen-like beautyMerlinMama does all things with Zen-like beautyMerlinMama does all things with Zen-like beautyMerlinMama does all things with Zen-like beautyMerlinMama does all things with Zen-like beautyMerlinMama does all things with Zen-like beauty
 
MerlinMama's Avatar
 
Posts: 487
Karma: 32554
Join Date: May 2014
Location: Canada
Device: Kobo Libra Colour
I can't imagine that searching up or down would change anything? Of course my knowledge of all this is EXTREMELY limited.

At any rate, I've fiddled with it and got it to work, so it's all good now. I might make a test entry just to see when I have time.
MerlinMama is offline   Reply With Quote
Old 08-16-2023, 12:53 PM   #5
lomkiri
Zealot
lomkiri ought to be getting tired of karma fortunes by now.lomkiri ought to be getting tired of karma fortunes by now.lomkiri ought to be getting tired of karma fortunes by now.lomkiri ought to be getting tired of karma fortunes by now.lomkiri ought to be getting tired of karma fortunes by now.lomkiri ought to be getting tired of karma fortunes by now.lomkiri ought to be getting tired of karma fortunes by now.lomkiri ought to be getting tired of karma fortunes by now.lomkiri ought to be getting tired of karma fortunes by now.lomkiri ought to be getting tired of karma fortunes by now.lomkiri ought to be getting tired of karma fortunes by now.
 
lomkiri's Avatar
 
Posts: 136
Karma: 1000102
Join Date: Jul 2021
Device: N/A
It's because of the \K. When you're searching upward, it looks for the last part of the regex (after the \K) and discard it, then it searches the first part

If you want that the regex works both directions, substitute the /K by a lookbehing condition :
Code:
(?<=Last Read:</b></dt><dd>)((<em>)?N/A(</em>)?| \d{1,2}/\d{2}/\d{4}| \d{1,2}-\d{2}-\d{4}|\s)
lomkiri is offline   Reply With Quote
Advert
Old 08-16-2023, 12:57 PM   #6
MerlinMama
Evangelist
MerlinMama does all things with Zen-like beautyMerlinMama does all things with Zen-like beautyMerlinMama does all things with Zen-like beautyMerlinMama does all things with Zen-like beautyMerlinMama does all things with Zen-like beautyMerlinMama does all things with Zen-like beautyMerlinMama does all things with Zen-like beautyMerlinMama does all things with Zen-like beautyMerlinMama does all things with Zen-like beautyMerlinMama does all things with Zen-like beautyMerlinMama does all things with Zen-like beauty
 
MerlinMama's Avatar
 
Posts: 487
Karma: 32554
Join Date: May 2014
Location: Canada
Device: Kobo Libra Colour
Ok, good to know. I always search down, but I do remember at one point noticing it was up, so that is probably it. I'll still test it, because actually seeing it will help drill it into my memory

Thanks
MerlinMama is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Help with S&R RegEx Function MerlinMama Editor 5 05-29-2022 02:23 AM
Help creating possible Regex-Function MerlinMama Editor 14 03-03-2020 05:53 AM
Predefined regex for Regex-function sherman Editor 3 01-19-2020 05:32 AM
regex function replacement The_book Sigil 5 12-09-2019 09:45 AM
Regex Function about «» and “” senhal Editor 8 04-06-2016 02:12 AM


All times are GMT -4. The time now is 12:29 PM.


MobileRead.com is a privately owned, operated and funded community.