Para combinar apenas o ambiente mais interno por Regex

0

Eu quero corresponder ao ambiente mais interno de begin{question} e seu correspondente end{question} .

Exemplo de dados

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

Minha saída esperada é

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

ou

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

ou

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

Como você pode combinar apenas o ambiente mais interno?

    
por Léo Léopold Hertz 준영 04.10.2014 / 22:45

2 respostas

3

Tente isto:

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

Explicação:

  • pcregrep : grep com expressões regulares compatíveis com Perl
  • -M : permitir que os padrões correspondam a mais de uma linha
  • (.|\n)*? : qualquer caractere normal . ou nova linha \n correspondido zero ou mais vezes . , no modo não ganancioso ? .

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}
    
por 04.10.2014 / 23:18
1

Você precisa que seja uma solução pura de regex, ou apenas perlish?

perl -lne 'print if(/^\begin{question}/ .. /^\end{question}/)'  file
    
por 05.10.2014 / 02:29