0
我正在读取.tex文件并根据另一个.tex文件保存的模式进行替换。我离开的分隔符是正则表达式perl匹配分隔的乳胶文本
\ket{
和正确的分隔符是
}
正则表达式\\ket\{(.+)\}
可以匹配
\ket{0}
但复杂的线条,如
$\ket{\bfG \bfP^L_{2ex}}$, and the real space, $\ket{\bfP^L_{2ex}}$
它匹配整个te XT
\bfG \bfP^L_{2ex}}$, and the real space, $\ket{\bfP^L_{2ex}
修改正则表达式
\\ket{([^{}]*|[^}])*}{1,2}
我可以检测所提到的复杂的线路,但在诸如
reciprocal lattice, $\ket{\bfG \bfP^L_{2ex}{3}{2}}$, and the real space, $\ket{\bfP^L_{2ex}}$
不起作用。我该如何解决这个问题?我必须阅读哪些算法/主题/书籍/教程来解决这样的问题?
第1步:停止使用[regexes](https://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags)。 https://en.wikipedia.org/wiki/Context-free_grammar#Examples – n0rd
请参阅[我应该怎么做当有人回答我的问题?](http://stackoverflow.com/help/someone-answers) – zdim