Skip to content

Instantly share code, notes, and snippets.

@jskherman
Created October 8, 2022 03:50
Show Gist options
  • Save jskherman/3256781ac22ec2d2092af46693f8f66a to your computer and use it in GitHub Desktop.
Save jskherman/3256781ac22ec2d2092af46693f8f66a to your computer and use it in GitHub Desktop.
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