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不支持expresspattern
。谁可以为我写一个JavaPattern
或者给我一些提示?
最佳答案
在java中,只有很少的修改。
1. Escape the backslash surrounding $
2. Make use of double quotation mark
您的新代码现在看起来像这样
Pattern.compile("(?=([^\\]?))(?:(?P<bound2>\\$\\$)|\\$)(.*?[^\\])(?:(?(bound2)\\$\\$|\\$))");
注意:确保导入模式类
关于java - 如何使用正则表达式查找字符串中的Latex表达式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32737389/