简体   繁体   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}$$";

Others told me a python pattern: 其他人告诉我一个python模式:

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

Expected: 预期:

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

But I use it in android,Java doesn't support express pattern .Who can write a Java Pattern for me or give me some tips? 但是我在android中使用它,Java不支持express pattern 。谁可以为我编写Java Pattern或给我一些提示?

In java, there are just little modifications. 在Java中,几乎没有修改。

1. Escape the backslash surrounding $ 1.转义$周围的反斜杠

2. Make use of double quotation mark 2.使用双引号

Your new code would now look like this 您的新代码现在看起来像这样

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

Note: Make sure you import your pattern class 注意:确保导入模式类

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM