Um nur die innerste Umgebung durch Regex abzugleichen

Um nur die innerste Umgebung durch Regex abzugleichen

begin{question}Ich möchte die innerste Umgebung von und das entsprechende abgleichen end{question}.

Beispieldaten

\section{Takayasu arteritis}

\begin{question}
{You get a patient. 
What do you notice first in this patient?}
Absence of peripheral pulse.
\end{question}

\begin{question}
{What was the first Takayasu case?}
Young woman in Asia with red vessels in the eye. 
So special eye diagnosis done. 
Affects eye.
\end{question}


Fever of unknown origin can be used when you do not know what is causing the disease. 

% Show cases in MedScape and ask class. 

Aneurysms. 


\subsection{Treatment}

\begin{question}
{What you should always include in Takayasu treatment? 
What are the symptoms?}
Blood pressure.
Aneurysms which will burst without treatment. 
So blood pressure decreasing drugs like beta blockers along in combination with other drugs.
\end{question}

Meine erwartete Ausgabe ist

\begin{question}
{You get a patient. 
What do you notice first in this patient?}
Absence of peripheral pulse.
\end{question}

oder

\begin{question}
{What was the first Takayasu case?}
Young woman in Asia with red vessels in the eye. 
So special eye diagnosis done. 
Affects eye.
\end{question}

oder

\begin{question}
{What you should always include in Takayasu treatment? 
What are the symptoms?}
Blood pressure.
Aneurysms which will burst without treatment. 
So blood pressure decreasing drugs like beta blockers along in combination with other drugs.
\end{question}

Wie kann man nur die innerste Umgebung anpassen?

Antwort1

Versuche dies:

pcregrep -M '\\begin{question}(.|\n)*?\\end{question}'

Erläuterung:

  • pcregrep: grep mit Perl-kompatiblen regulären Ausdrücken
  • -M: Muster dürfen mit mehr als einer Zeile übereinstimmen
  • (.|\n)*?: jedes normale Zeichen .oder jede neue Zeile wurde im nicht-gierigen Modus \nnull oder mehrmals gefunden ..?

Ergebnis:

\begin{question}
{You get a patient. 
What do you notice first in this patient?}
Absence of peripheral pulse.
\end{question}
\begin{question}
{What was the first Takayasu case?}
Young woman in Asia with red vessels in the eye. 
So special eye diagnosis done. 
Affects eye.
\end{question}
\begin{question}
{What you should always include in Takayasu treatment? 
What are the symptoms?}
Blood pressure.
Aneurysms which will burst without treatment. 
So blood pressure decreasing drugs like beta blockers along in combination with other drugs.
\end{question}

Antwort2

Muss es eine reine Regex-Lösung sein oder einfach nur Perlish?

perl -lne 'print if(/^\\begin{question}/ .. /^\\end{question}/)'  file

verwandte Informationen