Home > Net >  Regex for neuracache
Regex for neuracache

Time:11-05

I am trying to integrate an Neuracache style for questions and answers to do spaced repetition in my Obsidian notes (note taking app). So far I have this regex:

((?:[^\n][\n]?) ) #flashcard ?\n*((?:\n(?:^.{1,3}$|^.{4}(?<!<!--).*)) )

But it does not do quite what I want.

I would like to have a regex that will match the following:

How do we achieve A? #flashcard                    
To achieve A we need to do the following:          
                                                   
Do B                                               
                                                   
Do C                                               
                                                   
Finally do D                                       
                                                   
---


How do we achieve W? #flashcard                    
To achieve W we need to do the following:          
                                                   
Do Y                                               
                                                   
Do Z                                               
                                                   
<!--

We need to capture the question before flashcard and we need to capture the answer that will be in a new line right after #flashcard and right before --- or <!--.

The regex that I have does not accept multiple paragraphs as answers, nor does it take into account the ---

Any idea what I can do to improve my regex?

CodePudding user response:

Try:

^(.*?)\s*#flashcard\n([^:] ):.*?^(\S[^\n] )\s (?:---|<!--)

Regex demo.

This will extract the sentence before #flashcard, next line and the last answer before --- or <!--

  • Related