我想解析 .tex 文件的以下部分
\section{a}
some random lines with lot
of special characters
\subsection{aa}
somehthing here too
\section{b}
我想要包含 \section{a}
和 \section{b}
中的内容,所以我在 python 中尝试了以下代码
import re
a="my tex string mentioned above"
b=re.findall(r'\\section{a}.*\\section{b}',a)
print(b)
但我得到了b=[]
。我哪里错了?
最佳答案
您需要使用 re.DOTALL 标志来制作 .匹配换行符,如下所示:
b=re.findall(r'\\section{a}.*\\section{b}',a,re.DOTALL)
关于python - 使用 python re 库解析 Tex,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22384560/