View Single Post
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: 498
Karma: 32554
Join Date: May 2014
Location: Canada
Device: Kobo Sage
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