Created
October 8, 2022 03:50
-
-
Save jskherman/3256781ac22ec2d2092af46693f8f66a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
text = "Dummy text here with the cards" | |
# Regex for Basic Card with Extra field using #flashcard | |
basic_regex = r"((?:[^\n][\n]?)+) #flashcard ?\n*((?:\n(?:^.{1,3}$|^.{4}(?<!<!--)(?<!Extra: ).*)))(?:\nExtra: (.*))+" | |
# Regex for Cloze Card with Extra field | |
cloze_extra = r"((?:.+\n)*(?:.*==.*)(?:\n(?:^.{1,6}$|^.{7}(?<!<!--ID:)(?<!Extra: ).*))*)(?:\nExtra: (.*))?" | |
basics = re.find(basic_regex, text) | |
clozes = re.find(cloze_regex, text) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment