正则表达式 知乎Tex公式提取
import re
import urllib.parse
# https://learnbyexample.github.io/py_regular_expressions/groupings-and-backreferences.html
s = input("input string for formula conversion\n")
s = urllib.parse.unquote(s)
p_1 = "([\+]*)\+"
repl_1 = "\g<1> "
# s = re.sub(repr(p_1), repr(repl_1), s)
s = re.sub(p_1, repl_1, s)
p_2 = "\+\+"
repl_2 = "\+"
s = re.sub(p_2, repl_2, s)
print(s)
input("press a key to terminate")
本博文本意在于记录个人的思考与经验,部分博文采用英语写作,可能影响可读性,请见谅
本文来自博客园,作者:ZXYFrank,转载请注明原文链接:https://www.cnblogs.com/zxyfrank/p/15457517.html