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