RegEx flavor (in Find and Replace)

I have noticed that the regular expressions that Anki uses are not always the standard ones (cf. https://www.regular-expressions.info/ or Regular Expressions Tutorial - Getting started with Regular...).

So far, I have seen the following deviations:

Anything else?

Something such as “standard regex” does not exist. I have done quite some research on the topic as I have implemented myself a full-featured regex engine, and if anyone claims to have a “standard implementation”, they’re either lying or they don’t know what they’re saying.
The most “standard”-ish thing there is about regex is compliance with certain standards (such as the POSIX standard, or the Perl standard). The truth is that nobody fully follows even these standards (besides those who create them): at most some engine ensure that they are compatible with these.

So the issue when you are asking about deviations is: deviations with respect to what? Because there is no true standard, most regex implementations just give you their own specs. In the case of Anki, I think that it either uses Python’s or Rust’s engines (in the case of Rust, most probably the regex crate). The former is compatible (but does not comply with) with Perl regex, because it uses a backtracking algorithm, while the latter is compatible (but again, does not comply with) POSIX specs, because it uses DFA-based algorithm (well, sort of).

Besides that, the $i syntax is not regex-related. The second field in the search and replace dialog is not parsed as a regex. It’s just an Anki’s custom syntax.

(yes this is a recursive quote)

2 Likes

Thanks for clearing up my misconceptions. I’m a novice with regard to what’s going on “behind the UI”. I just noticed that the find and replace didn’t work like I expected it.

In the case of Anki, I think that it either uses Python’s or Rust’s engines (in the case of Rust, most probably the regex crate).

I appreciate your guess. If it is as you say, I would know where to look next time.

It’s documented here: Browsing - Anki Manual

It’s actually the replacement string syntax of the Rust crate.

5 Likes