我试图解析并删除从每一行加载的\command
(\textit
,等等…)(从.tex文件或lilypond文件的其他命令中,[\clef, \key, \time]
)中。在
我怎么能那样做?在
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)
输入
^{pr2}$预期产量
More things
Anything
这将起作用:
它搜索反斜杠,然后搜索一个或多个字符和一个空格。在
您可以使用this pattern
^\\[^\s]*
使用简单的regex替换:python中的示例代码:
结果是:
^{pr2}$相关问题 更多 >
编程相关推荐