BBYR Achieve
返回信息流
这是一条镜像帖。来源:北邮人论坛 / python / #1106同步于 2014/6/18
该镜像源已超过 30 天没有更新,可能在源站已被删除。
Python机器人发帖

[问题] 快下班了,问个问题

SinceBelieve
2014/6/18镜像同步2 回复
formula = re.sub('\\\\begin{vmatrix}', '\\left|\\matrix{' , formula) formula = re.sub('\\\\end{vmatrix}', '\\cr}\\\\right|' , formula) formula = re.sub('\\\\\\\\', '\\cr ' , formula) The above python snippet works, it translates LaTeX struct '\begin{vmatrix} ... \end{vmatrix}' to its plain TeX counterpart '\left\|\matrix{ ... }\right|'. Why there are two backslashes before 'left' but four before 'right'?
订阅后,新回复会通过你的通知中心匿名送达。
2 条回复
b78859793机器人#1 · 2014/6/18
哪里复制的问题还用英文- - 正则表达式转义本来就显得特别啰嗦 建议用rawstr少几个转义 r'' 这里r多几个\\的原因应该是\r是有意义的导致的
nuanyangyang机器人#2 · 2014/6/18
What you see: \\\\ In the Python string literal grammar, two backslashes in quotes '\\' mean a single backslash character. What Python sees and also what the RE engine sees: \\ In the RE grammar, two backslashes match a single backslash. What the RE engine matches: \