Add keywords cs: and ci: for case-sensitive or case-insensitive search

Case sensitivity in Anki is a mess. I would like a simple way to enable or disable case-sensitivity in search queries.

We already have ‘keywords’ like re: (regex), w: (whole word) and nc: (no combining). So I suggest the following:

  • Add the keywords ci: (case-insensitive) and cs: (case-sensitive). They will use the Unicode properties for casing.
  • Allow these keywords to be combined with other keywords in a search term. And while we’re at it, allow all tags to be combined, as long as they don’t contradict each other.

Examples of search queries:

  • ci:sch will match schijnheilig, Nederlandsche and Schiphol.
  • cs:Sch will match Schiphol, but not schijnheilig or Nederlandsche.
  • front:cs:w:Apple will match Apple in a Front field, but not apple, APPLE or Apples.
  • w:nc:he will match he, and , but not hemel or Nähe.
  • ci:nc:w:ἀμήν will match ἀμήν and Ἀμὴν.
  • cs:W*? will match What time is it? and Where?, but not why? or would you?.
  • cs:nc:ander_ will match ändern, andere, anders, but not Anders or ander.
  • ci:re:[jt]i will match Ji, Ti, ji, TI, etc.

To make this work, we will have to require an order on the keywords. re: must in any case be the last one. That is, everything after re: will be interpreted as part of the regex. Otherwise you might run into issues with the query "re:ci: a" – is this the case-sensitive regex ci: a or the case-insensitive regex a?

Combining ci: and cs: in one search term will raise an error, just like using lookaheads and lookbehinds in a regex currently does.

One tiny disadvantage is that searching on fields named ci or cs becomes impossible, as this is currently if you name a field deck for instance. But I think the user should just be warned that they won’t be able to search on that field if they want to name a field after a keyword like w, nc, etc.

It’s hard to justify the extra complexity this would require, given that in the majority of cases a case-insensitive search is fine, and you can already achieve case-sensitive searches via the regex search mode.

1 Like

Unless i’m mistaken, regex searches can only ever be case-insensitive ((?i) is prepended and can’t be overridden by the following query)

re:(?-i)… should work, and is documented in the manual :slight_smile:

2 Likes

TIL :sweat_smile: