A regex to remove Anki's cloze markup
Recently, someone asked a question on r/Anki about changing and existing cloze-type note to a regular note. Part of the solution involves stripping the cloze markup from the existing cloze’d field. A cloze sentence has the form Play {{c1::studid}} games.
or Play {{c1::stupid::pejorative adj}} games.
To handle both of these cases, the following regular expression will work. Just substitute for $1
.
\{\{c\d::([^:\}]+)(?:::+[^\}]*)*\}\}
However, the Cloze Anything markup is different. It uses (
and )
instead of curly braces. If we want to flexibly remove both the standard and Cloze Anything markup, then our pattern would look like:
[\{\(]{2}c\d+::([^:\}\)]++)(?:::[^:\}\)]+)?[\}\)]{2}