Para coincidir solo con el entorno más interno mediante Regex

Para coincidir solo con el entorno más interno mediante Regex

Quiero hacer coincidir el entorno más interno de begin{question}y su correspondiente end{question}.

Datos de ejemplo

\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}

Mi resultado esperado es

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

o

\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}

o

\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}

¿Cómo puedes igualar sólo el entorno más interno?

Respuesta1

Prueba esto:

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

Explicación:

  • pcregrep: grep con expresiones regulares compatibles con Perl
  • -M: Permitir que los patrones coincidan con más de una línea
  • (.|\n)*?: cualquier carácter normal .o nueva línea \nque coincida cero o más veces ., en modo no codicioso ?.

Resultado:

\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}

Respuesta2

¿Necesita que sea una solución de expresiones regulares pura o simplemente perlish?

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

información relacionada