정규식을 통해 가장 안쪽 환경만 일치시킵니다.

정규식을 통해 가장 안쪽 환경만 일치시킵니다.

가장 안쪽 환경 begin{question}과 그에 상응하는 end{question}.

샘플 데이터

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

내 예상 결과는

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

어떻게 가장 내부 환경에만 일치할 수 있습니까?

답변1

이 시도:

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

설명하다:

  • pcregrep: grep Perl 호환 정규 표현식
  • -M: 패턴이 여러 줄과 일치하도록 허용
  • (.|\n)*?: non-greedy 모드에서는 일반 문자 .나 개행 문자가 \n0번 이상 일치합니다..?

결과:

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

답변2

순수한 정규식 솔루션이 필요합니까, 아니면 그냥 사라질 것입니까?

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

관련 정보