簡體   English   中英

如何使用正則表達式在字符串中查找Latex表達式

[英]How to use regular expressions to find the Latex expression in a string

private static final String TEXT = "this a test 1: $\\$$,test 2: $\\underline{\\rm defund}$, test 3:$$\\underline{\\rm defund}$$";

其他人告訴我一個python模式:

re.compile(r'(?=([^\\]?))(?:(?P<bound2>\$\$)|\$)(.*?[^\\])(?:(?(bound2)\$\$|\$))', re.S)

預期:

$\$$ or \$, $\underline{\rm defund}$ or \underline{\rm defund}

但是我在android中使用它,Java不支持express pattern 。誰可以為我編寫Java Pattern或給我一些提示?

在Java中,幾乎沒有修改。

1.轉義$周圍的反斜杠

2.使用雙引號

您的新代碼現在看起來像這樣

Pattern.compile("(?=([^\\]?))(?:(?P<bound2>\\$\\$)|\\$)(.*?[^\\])(?:(?(bound2)\\$\\$|\\$))");

注意:確保導入模式類

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM