【发布时间】:2014-06-22 08:35:22
【问题描述】:
我正在尝试从加载的每一行(来自 .tex 文件或来自 lilypond 文件的其他命令为 [\clef, \key, \time])解析并删除任何 \command(\textit 等...)。
我该怎么做?
我尝试过的
import re
f = open('example.tex')
lines = f.readlines()
f.close()
pattern = '^\\*([a-z]|[0-9])' # this is the wrong regex!!
clean = []
for line in lines:
remove = re.match(pattern, line)
if remove:
clean.append(remove.group())
print(clean)
示例
输入
#!/usr/bin/latex
\item More things
\subitem Anything
预期输出
More things
Anything
【问题讨论】:
标签: python regex latex lilypond