繁体   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