Filter and Search and Replace do not work correctly

Trying to search for various patterns in the note browser sometimes works correctly but sometimes results only in single hit for the note that is currently displayed on the review screen or was displayed last. The same pattern fails in search and replace.

I couldn’t figure out what could be causing it specifically, but all the failed searches are related to a bad search and replace that I was trying to fix. The two string that were introduced into one field were &lt; &gt; and <!-- -->. I have tried to use different substrings of the above (for example, two minuses), but all my efforts were unsuccessful. In one or two cases the search resulted in more than one note but still did not find them all.

I see several previous posts (for example, from 2020 and 2023) describing similar symptoms but the mentioned workarounds didn’t work for me.

Have you taken a look at Searching - Anki Manual?

If you could clarify exactly what your search string is (and whether it’s in the search box or in Find-and-Replace, if those are different) – perhaps folks could help you troubleshoot it.

I have mentioned that two minuses do not find all of the instances.

Here are few more:

--
<!
--\s--
->
&lt;
&gt;

I have also attempted to backslash anything that could potentially be special symbol.

In addition, you could have noticed me mentioning that the patterns do find the match in one note but not in the others. This is clear indication that the problem is not with the pattern itself but with the software .

Also, I do programming for living and for fun and am familiar with regular expressions pretty well. Here’s one example of regular expression written by me:

s/(^.+?$)\n(\d+)\n(\1)/ren *%VAR%E0$2*.ext \"%VAR%E0$2 $1.ext\"/msg

This is in essence a bug report and not a request to help with regular expressions. I understand it is pretty vague, but, as I have mentioned, I do not see any patterns, except, that all the notes I’m trying to find have been changed by the previous Search and Replace operation.

I fully expect to be contacted by a developer to do some additional digging.

Thank you!

P.S. The debug console does not show any messages during the search attempts.

These are working fine for me (in the search box) by following the instructions at the link I gave you.

These are working fine for me (in the search box) as they are – but they match different things. For instance, depending on whether the < character is used in an HTML tag, or the &lt; HTML entity is used to represent the actual character in your text. (See the link I gave you more about that as well.)

Here’s an example of a field that would match both < and &lt;

You can see the underlying HTML for a field by clicking < > above the field.

If you can give us an example [all as code-blocked text] of a search string where that is happening – as well as the visual/display view and HTML view of the field that is matching and of the field that is not matching, but should – let’s see if anyone can reproduce it.

Please also include your complete version information from Help > About > “Copy Debug Info”.

I understand that you intend this as a bug report. But a developer can’t do much with something this vague. Someone needs to provide a reproducible example of search failing.

2 Likes
Anki 25.09.2 (3890e12c) (ao)
Python 3.13.5 Qt 6.9.1 PyQt 6.9.1
Platform: Windows-11-10.0.26100-SP0

===Add-ons (active)===
(add-on provided name [Add-on folder, installed at, version, is config changed])
'' ['anki-launcher', 0, 'None', '']
AJT Merge Notes - Merge and Duplicate notes ['1425504015', 2025-10-14T19:53, 'None', mod]
Adjust Sound Volume ['2123044452', 2023-12-25T09:00, 'None', mod]
Advanced Copy Fields ['1898445115', 2024-01-08T12:01, 'v0.4.01', '']
Anki JavaScript API ['1490471827', 2021-02-19T15:54, 'None', '']
AnkiConnect ['2055492159', 2025-11-09T14:40, 'None', '']
AnkiWebView Inspector ['31746032', 2023-06-27T15:26, 'None', '']
CSS Injector - Change default editor styles ['181103283', 2023-02-21T16:15, 'None', '']
Customize Keyboard Shortcuts-Added settings Control Panel and file path ['1762336370', 2025-05-11T00:42, 'None', mod]
FSRS Helper Postpone  Advance  Load Balance  Easy Days  Disperse Siblings ['759844606', 2025-11-06T22:32, 'None', mod]
Japanese Conjugation ['546479171', 2025-07-12T10:41, 'None', mod]
Jlab Study Japanese with moviessubs2srsRomajiKana ['2110939339', 2025-05-27T13:43, 'None', '']
Large and Colorful Buttons ['1829090218', 2018-10-02T13:41, 'None', '']
Show Seconds in Card Creation Date ['1830141625', 2024-03-05T05:01, 'None', '']
Simple Forvo Audio Downloader ['560814150', 2024-09-08T09:03, 'None', mod]

===IDs of active AnkiWeb add-ons===
1425504015 1490471827 1762336370 181103283 1829090218 1830141625 1898445115 2055492159 2110939339 2123044452 31746032 546479171 560814150 759844606

===Add-ons (inactive)===
(add-on provided name [Add-on folder, installed at, version, is config changed])
Override shortcuts ['604635542', 2023-06-05T12:35, '1.0.0', '']

If it’s only happening on one machine and in one deck, it’s probably not “reproducible” in a way that would lead to a bug fix. We don’t have anyone available to do screenshare with you – but we do have access to your collection for support purposes. What I asked for – a relevant example as text – is what we need. Not screenshots.

1 Like

Please stop posting screenshots. This isn’t helpful at all.

The only thing I’ve discovered from your screenshots so far is that you’re actually asking about regex searches – which you didn’t mention in your original post. But, as I said – give us examples of the search strings that aren’t working, and of the text they are/aren’t working for.

1 Like

PS BTW, disabling plugins does not make the issue go away.

Could you please post step-by-step instructions for how someone (who doesn’t have access to your deck) can reproduce the bug behavior?

For example, starting with an empty deck, describe what Note to create, the exact text to put into the fields.

Then, describe the search you are attempting, the exact text you are entering into the search.

If you do this, I will follow your instructions and see if I am able to reproduce the bug.

2 Likes

Actually, you may want to try searching my deck and see if it is reproducible that way. That would at least tell if serializing it through the website preserves the issue. If not, it might be related to the way it is stored in the database.

Actually, saying that made me open the database in DB Browser for SQLite…

And it looks like this is also a problem in database as well.

Since I can’t search specific field in database it does find double minus in all records but as soon as I present the string that only exist in the target field I do see the same behavior:

select * from notes where mid = '1725715483025' and flds like '%-- -%'

Finds only a single note just like Anki finds a single note for:

-- -

What I could see is that:

is stored in database like this after search and replace but before opening it in the browser:

but is converted to this after the note is viewed in the browser:

Trying to make heads and tails of the two… It seems like there could be some delayed replacement logic or something… Since it looks like the first quote contains (at least parts of) the pre-replacement text and no replacement text - hence failure to find it. But once the note is viewed in the browser the replacement is finalized and the search is now able to succeed.

PS @BenJamesBen Is this enough or would you still prefer to have step by step instruction to reproduce it. Given the above information there’s a chance I might be able to trigger this bug from scratch…

This also gave me an idea for a workaround.

  1. In the browser search for the original text that was supposed to be replaced by the previous search and replace operation (in my case I searched for rt).
  2. Step through all the notes so they are open in the browser (sucks if it is a lot of notes but in my case it was only 65 notes out of some 3k notes currently, so it was not too bad).
  3. Now search and replace as originally attempted.
1 Like

I guess I should not mark this as a solution since it is not one and it marks thread as solved while the original bug still needs to be fixed…

Still need the same things from you.

1 Like

It is not search string related. Any string would cause the issue given the circumstances. It is also irrelevant if it is plain search or regular expression search.

Please see the analysis of the problem in my post above.

Anki 25.09.2 (3890e12c) (ao)
Python 3.13.5 Qt 6.9.1 PyQt 6.9.1
Platform: Windows-11-10.0.26100-SP0

===Add-ons (active)===
(add-on provided name [Add-on folder, installed at, version, is config changed])
'' ['anki-launcher', 0, 'None', '']
AJT Merge Notes - Merge and Duplicate notes ['1425504015', 2025-10-14T19:53, 'None', mod]
Adjust Sound Volume ['2123044452', 2023-12-25T09:00, 'None', mod]
Advanced Copy Fields ['1898445115', 2024-01-08T12:01, 'v0.4.01', '']
Anki JavaScript API ['1490471827', 2021-02-19T15:54, 'None', '']
AnkiConnect ['2055492159', 2025-11-09T14:40, 'None', '']
AnkiWebView Inspector ['31746032', 2023-06-27T15:26, 'None', '']
CSS Injector - Change default editor styles ['181103283', 2023-02-21T16:15, 'None', '']
Customize Keyboard Shortcuts-Added settings Control Panel and file path ['1762336370', 2025-05-11T00:42, 'None', mod]
FSRS Helper Postpone  Advance  Load Balance  Easy Days  Disperse Siblings ['759844606', 2025-11-06T22:32, 'None', mod]
Japanese Conjugation ['546479171', 2025-07-12T10:41, 'None', mod]
Jlab Study Japanese with moviessubs2srsRomajiKana ['2110939339', 2025-05-27T13:43, 'None', '']
Large and Colorful Buttons ['1829090218', 2018-10-02T13:41, 'None', '']
Show Seconds in Card Creation Date ['1830141625', 2024-03-05T05:01, 'None', '']
Simple Forvo Audio Downloader ['560814150', 2024-09-08T09:03, 'None', mod]

===IDs of active AnkiWeb add-ons===
1425504015 1490471827 1762336370 181103283 1829090218 1830141625 1898445115 2055492159 2110939339 2123044452 31746032 546479171 560814150 759844606

===Add-ons (inactive)===
(add-on provided name [Add-on folder, installed at, version, is config changed])
Override shortcuts ['604635542', 2023-06-05T12:35, '1.0.0', '']

It’s nice that you are doing some digging on your own. But how should we even start with reproducing the issue you are having without steps to reproduce? Maybe the issue you are seeing can be easily solved but at that point I still have no idea what exactly you even did to trigger the issue you are seeing.

Also: there are several devs here (most of them are volunteers) that read the posts here. If you provide all of the necessary info, especially those you have been asked to provide, then a dev can have a look and potentially fix it.

Maybe start with the usual template:

  1. Steps to reproduce
  2. Actual Behavior
  3. Expected Behavior
  4. Additional Info / Screenshots / Videos, ect. if applicable
  5. Version Info (you sent that one in the last post)
2 Likes

Not completely clear at this point. But it involves using using find and replace functionality and then trying to further modify what the “replace” part of the first replace. I’m able to reproduce it sometimes by doing the above but it does not happen 100% of the time. BTW there’s another nasty thing that find and replace does - automatic change of the field after the replacement - if the replacement meddles with the html tags the find and replace will then try to “fix“ it and screws things pretty badly. I’ll try to make another post about that one specifically later.

The notes table does not contain the replacement text in the fld field which results in filtering and searching functionality failing to find any substring unique to that replacement text.

Filtering and searching able to find all occurrences of the replacement text substring.

I do not have a setup for video and I have been asked not to post screenshots so I have deleted those posts. As for additional info I have provided all the information I was able to figure out up to that point.

New additional information: this seems to be related to the SQLite as the failure to find the notes persists across Anki restarts and, I guess, Anki does not save its state otherwise. If it does do that - this problem might be related to that.

Rant mode on:

I am a developer myself and quite familiar how it is to chase hard to reproduce bugs. However I’m earning my living that way instead of doing it for free and very inclined to figuring things out so I might be biased but… never mind… I do not want to say something that could be taken the wrong way…

I do appreciate constructive conversation, but if I’m asked the same question over and over again, it feels like what I write in not being read. If something needs to be confirmed or verified, it is fine as well, but, please, make an effort to show that what I have written has been read by saying something like “could you confirm”, “could you double-check”, etc. …

I’ve tried to consolidate what I know before and in this post and have deleted my observations that turned out to be a red herring in order to make things easier for the developers and am still very eager to cooperate on figuring out and fixing this bug. But, please, try not to ask the same question over and over again.

Rant off(?)

If I’m able to figure out bullet proof way to reproduce the issue I’ll write and idiot’s guide to reproducing it.

Also, there might be something going on with my SQLite database instance specifically and if anyone familiar with SQLite experience wants to take a look at it I could share that as well.

Looks like I need to use the second bug to make the first one to appear consistently. So, two for the price of one:

  1. Create and switch to a new profile named test

  2. Add two basic notes to the default deck with Front:1/Back:a and Front:2/Back:a


  3. Open browser

  4. Select all notes

  5. Open Find and Replace dialog and fill with Find:a, Replace:<a, In:Back, tick Selected notes only and Treat input as regular expression, untick Ignore case, and then click OK

  6. In the browser click on the first note and click <> of the Back field

  7. Do you see < body=""></a<> in there? Why? I didn’t ask for it? It may be ok to do some auto inserts when the field is edited manually but when I’m doing find and replace it is just wrong. Not to mention it inserts garbage in this case…

  8. But ok… Let’s try to fix this… Let’s find all the notes that have body in that field. Apply Back:re:body filter in the browser

  9. Ok… One note… Could it be that only one note has been changed? Let’s check the other one… Clear the filter. And check the other note.

  10. It does have the body string in it. So, why had it been excluded by the filter?

2 Likes

Thanks!

I cannot say why this happens, but use &lt;a in the find and replace dialog instead and it will work.

I am guessing that the regex search is always changing the html code instead of the user visible string, but <a isn’t valid html. Not sure why <a< body=""></a<> gets inserted specifically instead of just closing the <a part, but the auto close had probably been implemented in the past to prevent issues.

E.g. just adding a random <a would cause the card to render blank, which had been solved by closing the tags properly (and yes, <a< body=""></a<> may look weird and its existance is possibly a bug, but it solves the issue of blank cards being rendered).

I cannot answer this, though. That certainly doesn’t make sense to me.

I was able to reproduce the “<a” bug, and I found an easier way to reproduce it:

  1. Browse and open an existing card,
  2. For any Note field, toggle the HTML Editor for that field to expose it.
  3. In the HTML Editor field, enter <a
  4. Close and re-open the Note. Observe that the HTML Editor field now incorrectly contains <a< body=""></a<>.

So, I can reproduce the second bug. But regarding the first bug, I’m still not sure exactly what it looks like or how to test for it.

(Sorry if you were feeling frustrated by our questions. But, from our perspective, we were repeating questions because we weren’t getting answers to them. You probably thought that you were answering them, but your responses just didn’t provide the information that was requested.)

If you’ll look through the write up you’ll see that &lt;a doesn’t exist in that field post replacement. So, no, searching for that would not help. Try it.

In any case you are missing the point. If I accidentally screw the html content of the field in such a way that Anki inserts arbitrary text, I have no way of fixing it because Anki will not find that text anymore.