At the moment, the syntax for searching cards has quite a few inconsistencies and undocumented behaviour.
\matches nothing but doesn’t throw an error, either.
\and then anything).
%is treated like a wildcard.
(can be matched anywhere, but
)only in quotes.
- If unquoted,
\"text\"throws an error.
(a)(b)are all valid, but
tag:"a c"doesn’t match anything, but
tag:"a c*"(apart from matching the expected) match cards with tags
cunless they have a tag
:can’t be matched, either. A funny workaround is
I would like to redress these issues but for this there needs to exist a fixed and consistent syntax without ambiguities. To achieve that, I want to put forward the following list of clarifications and changes (numbers only for ease of reference):
\is always an escape character. An undefined escape sequence is an error.
- The defined escape sequences are:
\). They are required to match the corresponding special character.
%is not a special character.
- All of the escape sequences might be used outside quotes.
)inside quotes is optional.
:is optional if it is preceded (not necessarily immediately) by another unescaped
:in the containing string.
- Text preceded by certain keywords (
re:) might deviate from all of the above, but escaping
"is obligatory. Ergo, quoted text is always terminated by a
"preceded by an even number (including 0) of
tag:doesn’t work across tag boundaries (spaces).
- A string starting with
:is an error because the empty string can neither be a keyword nor a field name.
What do you think? Will implementing this will break anything (that is not broken, yet)? Or have I missed something that also should be included in this list? All feedback is welcome.
By the way, I’ve tried to be as permissive as possible because I know some users may depend on the status quo. But personally, I think Anki would benefit from a stricter rule set (in the search context and in general) because this would allow for more helpful feedback to the user if something goes wrong. An example would be enforcing white space between search strings.